Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge micropython v1.19.1 #8281

Merged
merged 682 commits into from
Aug 21, 2023
Merged

Conversation

dhalbert
Copy link
Collaborator

@dhalbert dhalbert commented Aug 14, 2023

Merging MicroPython v1.19.1

Just before this PR was pushed, my manuals tests showed that the silabs port fails when compiling, and some tests fail when make test is done in port/unix. The other ports are compiling. I did some smoke tests on a CPX: a program that played Jingle Bells and made NeoPixel animations happened to be on that CPX, so that tested a bunch of things including frozen modules and generators. Also I did some simple gc testing by creating large bytearrays.

More failures may appear when the CI runs.

Major changes from upstream

  • New macro mp_obj_malloc() allocates an object and sets its type. This was straightforward to incorporate.
  • The REGISTER_MODULE mechanism has changed extensively; took changes, causing many changes in makemoduledefs.py, mkrules.mk, and other places.
  • MICROPY_MODULE_ATTR_DELEGATION features added. Lots of churn in objmodule.c.
  • qstr storage is different. QENUM is now QDEF. Qstr lengths and hashes were factored out into separate arrays, and there's a lot of qstr churn in the .mk files.

Major changes made that affect CircuitPython-only features

Tooling

  • make V= is now any combination of these space-separated keywords: "steps commands rules" instead of the old 0, 1, or 2. rules is new and gives you the makefile line that is doing the step.

Attempts made to get closer to MicroPython sources

  • I tried to remove gratuitous changes we had made to make the sources, especially in py/ be closer to MicroPython. For instance, "SPDX" copyright lines were restored to the original.
  • I restored '#if'dcode from upstream that we will never use, such asdupterm` features that we always have turned off. This makes for fewer diffs between files.

For v1.20 merge

  • Our PR gc.c: Ensure a gap of one byte before the finaliser table. #5245 made a bunch of changes in gc.c. These were incorporated, and will be in the v1.20 merge.
  • Watch for lib/re1.5 changes after v1.19.1. We have changes as well, so this merge may be complicated.
  • I incorporated @jepler's type object space-savings ("extended fields"). This was done in a somewhat different way in v1.20, and I think we are just going to take that way when we get there.
  • In 'ulab, CircuitPython-specific toggle for module registration can be removed.

Things still to fix

  • Silabs: The silabs port does not build. The port has make-rule differences from the other ports, to accommodate idiosyncrasies in the silabs SDK. For instance, their ECHO is different from ours. These seem to be breaking dependency ordering for the genhdr generated files. This causes genhdr/mpversion.h not to be built in time. I tried to fix, but didn't succeed yet.
  • The dependency ordering for qstr generated and genhdr is kind of a mess in general. his is partly inherited from upstream. There are many order dependencies, maybe too many, and I think this maybe could be cleaned up. See tricky FORCE usage, and SRC_QSTR and OBJ_EXTRA_ORDER_DEPS usage. I had to add OBJ_EXTRA_ORDER_DEPS to get some things build in the right order. I think it could be simpler.
    I think there may still be some non-determinancy, which might be what is breaking the silabs build. Try building -j1 vs -j<n>.
  • Tests failed locally. The viper tests are running, though I have tried to turn them off (and they were turned off before in our builds).
  • I don't know if we care about the "native" code generation enough to try to make it work. We made changes in generators and tracebacks which may need extra work in the native code implementation to work.

Aspirations

  • I would like to see fewer differences between what we have and upstream, especially in py/ and extmod/.
  • Let's try to PR our changes upstream when possible, including minor things like spelling fixes. Let's try to keep in sync more. If upstream takes our changes, but with edits, let's incorporate those edits. Major things we might contribute back:
    • Our fancier tracebacks
    • generator improvments
    • async/await impl, which includes an explicit __await__()
    • module attributes or some property stuff -- I forget the details.

Notes

  • I made one pass with git mergetool, and then did another pass with manual merging to re-check things, because the auto-merging was sometimes wrong, and sometimes I wanted to revert more things to what was in upstream (like copyright lines.)
    This little alias was useful. adafruit/circuitpython is set to main, circuitpython is where I was merging, and micropython was set to v1.19.1.
3meld() {
    pushd ~/repos
    meld adafruit/circuitpython/$1 circuitpython/$1 micropython/$1 &
    popd
}

dpgeorge and others added 30 commits May 17, 2022 14:25
Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: Damien George <damien@micropython.org>
Some architectures (like esp32 xtensa) cannot read byte-wise from
executable memory.  This means the prelude for native functions -- which is
usually located after the machine code for the native function -- must be
placed in separate memory that can be read byte-wise.  Prior to this commit
this was achieved by enabling N_PRELUDE_AS_BYTES_OBJ for the emitter and
MICROPY_EMIT_NATIVE_PRELUDE_AS_BYTES_OBJ for the runtime.  The prelude was
then placed in a bytes object, pointed to by the module's constant table.

This behaviour is changed by this commit so that a pointer to the prelude
is stored either in mp_obj_fun_bc_t.child_table, or in
mp_obj_fun_bc_t.child_table[num_children] if num_children > 0.  The reasons
for doing this are:

1. It decouples the native emitter from runtime requirements, the emitted
   code no longer needs to know if the system it runs on can/can't read
   byte-wise from executable memory.

2. It makes all ports have the same emitter behaviour, there is no longer
   the N_PRELUDE_AS_BYTES_OBJ option.

3. The module's constant table is now used only for actual constants in the
   Python code.  This allows further optimisations to be done with the
   constants (eg constant deduplication).

Code size change for those ports that enable the native emitter:
   unix x64:   +80 +0.015%
      stm32:   +24 +0.004% PYBV10
    esp8266:   +88 +0.013% GENERIC
      esp32:   -20 -0.002% GENERIC[incl -112(data)]
        rp2:   +32 +0.005% PICO

Signed-off-by: Damien George <damien@micropython.org>
Prior to this commit, all qstrs were required to be allocated (by calling
mp_emit_common_use_qstr) in the MP_PASS_SCOPE pass (the first one).  But
this is an unnecessary restriction, which is lifted by this commit.
Lifting the restriction simplifies the compiler because it can allocate
qstrs in later passes.

This also generates better code, because in some cases (eg when a variable
is closed over) the scope of an identifier is not known until a bit later
and then the identifier no longer needs its qstr allocated in the global
table.

Code size is reduced for all ports with this commit.

Signed-off-by: Damien George <damien@micropython.org>
To make sure there are no dangling references to the lists, and the GC can
reclaim heap memory.

Signed-off-by: Damien George <damien@micropython.org>
The recent rework of bytecode made all constants global with respect to the
module (previously, each function had its own constant table).  That means
the constant table for a module is shared among all functions/methods/etc
within the module.

This commit add support to the compiler to de-duplicate constants in this
module constant table.  So if a constant is used more than once -- eg 1.0
or (None, None) -- then the same object is reused for all instances.

For example, if there is code like `print(1.0, 1.0)` then the parser will
create two independent constants 1.0 and 1.0.  The compiler will then (with
this commit) notice they are the same and only put one of them in the
constant table.  The bytecode will then reuse that constant twice in the
print expression.  That allows the second 1.0 to be reclaimed by the GC,
also means the constant table has one less entry so saves a word.

Signed-off-by: Damien George <damien@micropython.org>
Because the test modifies the (now) bytearray object, and if it's a bytes
object it's not guaranteed that it can be modified, or that this constant
object isn't used elsewhere.

Signed-off-by: Damien George <damien@micropython.org>
Signed-off-by: Damien George <damien@micropython.org>
Now that constant tuples are supported in the parser, eg (1, True, "str"),
it's a small step to allow anything that is a constant to be used with the
pattern:

    from micropython import const

    X = const(obj)

This commit makes the required changes to allow the following types of
constants:

    from micropython import const

    _INT = const(123)
    _FLOAT = const(1.2)
    _COMPLEX = const(3.4j)
    _STR = const("str")
    _BYTES = const(b"bytes")
    _TUPLE = const((_INT, _STR, _BYTES))
    _TUPLE2 = const((None, False, True, ..., (), _TUPLE))

Prior to this, only integers could be used in const(...).

Signed-off-by: Damien George <damien@micropython.org>
When opening a new issue the following selection is now shown:
- Bug reports
- Feature requests
- Security issue
- Documentation issue
- Link to forum
- Link to docs
- Link to downloads
For example, ussl can come from axtls or mbedtls. If neither are enabled
then don't try and set an empty definition twice, and only include it
once in MICROPY_REGISTERED_MODULES.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
_onewire, socket, and network were previously added by the port rather
than objmodule.c.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This functionality is now replaced with MP_REGISTER_MODULE.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
@jepler
Copy link
Member

jepler commented Aug 20, 2023

yay we've finally gotten to building boards during CI :) 🚀

jepler added 15 commits August 20, 2023 10:15
this saves changing uses of it in ports/ and if we re-add ll later, it'll
make it easier to find the places that needed long-lived allocation.
This seems to only be defined in cmsis files for M7 family MCUs, so
it's not for e.g., makerdiary_m60_keyboard which enables loading of native
code. Lower MCUs don't ever have icache, so the default is "off".
Here's why this helps fix the build error:
If this file does not exist or is out of date, then it is generated
and then the Makefile is re-read.

I don't know why this worked before but stopped now; it must have
to do with the rework of header generation in the MP build system.
.. and update asyncio to a version that uses the old names but has other
new asyncio improvements.
@dhalbert dhalbert marked this pull request as ready for review August 21, 2023 21:45
@dhalbert dhalbert requested a review from jepler August 21, 2023 21:45
@dhalbert
Copy link
Collaborator Author

Tested on a bunch of representative boards. Not tested on broadcom or silabs. Spresense failed, but I think that may be an SDK version skew problem, not necessarily related to this PR. All others passed a simple smoke test: random program running or microcontroller.cpu.temperature.

Copy link
Member

@jepler jepler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's ready! .. for others to test

@dhalbert dhalbert merged commit 282e93d into adafruit:main Aug 21, 2023
@dhalbert dhalbert deleted the merge-micropython-v1.19.1 branch August 22, 2023 01:31
@dhalbert
Copy link
Collaborator Author

The merge doc build is failing in a weird way: https://github.com/adafruit/circuitpython/actions/runs/5932484043/job/16088305509#step:8:1

@bill88t
Copy link

bill88t commented Aug 23, 2023

So far I have found 0 breaking changes (other than the need to regen all .mpy's).

.mpy sizes reduced a good bit:
mpy-cross-8.1.0: 73.3kb
mpy-cross-8.2.0-87-ge08ad22ef (current master): 68.0kb

Speed to have increased a bit, but I still haven't made benchmarks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.