tinygo/transform
Ayke van Laethem 734613c20e transform: introduce check for method calls on nil interfaces
I ran into an issue where I did a method call on a nil interface and it
resulted in a HardFault. Luckily I quickly realized what was going on so
I could fix it, but I think undefined behavior is definitely the wrong
behavior in this case. This commit therefore changes such calls to cause
a nil panic instead of introducing undefined behavior.

This does have a code size impact. It's relatively minor, much lower
than I expected. When comparing the before and after of the drivers
smoke tests (probably the most representative sample available), I found
that most did not change at all and those that did change, normally not
more than 100 bytes (16 or 32 byte changes are typical).

Right now the pattern is the following:

    switch typecode {
    case 1:
        call method 1
    case 2:
        call method 2
    default:
        nil panic
    }

I also tried the following (in the hope that it would be easier to
optimize), but it didn't really result in a code size reduction:

    switch typecode {
    case 1:
        call method 1
    case 2:
        call method 2
    case 0:
        nil panic
    default:
        unreachable
    }

Some code got smaller, while other code (the majority) got bigger. Maybe
this can be improved once range[1] is finally allowed[2] on function
parameters, but it'll probably take a while before that is implemented.

[1]: https://llvm.org/docs/LangRef.html#range-metadata
[2]: https://github.com/rust-lang/rust/issues/50156
2020-05-28 13:42:36 +02:00
..
testdata transform: introduce check for method calls on nil interfaces 2020-05-28 13:42:36 +02:00
allocs.go fix incorrect starting value for optimized allocations in a loop 2019-11-13 16:45:09 +01:00
allocs_test.go all: refactor heap-to-stack transform into the transform package 2019-09-15 21:26:27 +02:00
coroutines.go transform (coroutines): remove map iteration from coroutine lowering pass 2020-04-12 16:54:40 +02:00
errors.go refactor coroutine lowering and tasks 2020-03-17 12:16:10 +01:00
func-lowering.go transform: fix debug information in func lowering pass 2020-05-07 08:24:14 +02:00
func-lowering_test.go compiler: refactor func lowering to the transform package 2019-12-04 22:19:49 +01:00
gc.go transform (gc): track phi nodes in stack slots 2020-04-02 15:06:58 +02:00
gc_test.go compiler: move GC passes to the transform package 2019-11-25 09:14:31 +01:00
globals.go compiler: move NonConstGlobals pass to transform package 2020-03-19 19:56:08 +01:00
globals_test.go compiler: move NonConstGlobals pass to transform package 2020-03-19 19:56:08 +01:00
goroutine_test.go refactor coroutine lowering and tasks 2020-03-17 12:16:10 +01:00
interface-lowering.go transform: introduce check for method calls on nil interfaces 2020-05-28 13:42:36 +02:00
interface-lowering_test.go transform: replace panics with source locations 2020-03-24 15:07:55 +01:00
interrupt.go runtime/fe310: add support for PLIC interrupts 2020-01-27 19:58:39 +01:00
interrupt_test.go all: add compiler support for interrupts 2020-01-20 21:19:12 +01:00
llvm.go runtime/fe310: add support for PLIC interrupts 2020-01-27 19:58:39 +01:00
maps.go all: move OptimizeMaps to transforms and add tests 2019-09-15 21:26:27 +02:00
maps_test.go all: move OptimizeMaps to transforms and add tests 2019-09-15 21:26:27 +02:00
optimizer.go compiler, transform: remove runtime.isnil hack 2020-03-27 07:38:16 +01:00
panic.go compiler: move ReplacePanicsWithTrap pass to transforms 2019-11-16 18:41:28 +01:00
panic_test.go compiler: move ReplacePanicsWithTrap pass to transforms 2019-11-16 18:41:28 +01:00
reflect.go transform: make reflection sidetables constant globals 2019-12-21 22:59:23 +01:00
stringtobytes.go compiler: move OptimizeStringToBytes to transform package 2019-09-22 08:25:50 +02:00
stringtobytes_test.go compiler: move OptimizeStringToBytes to transform package 2019-09-22 08:25:50 +02:00
transform.go all: refactor heap-to-stack transform into the transform package 2019-09-15 21:26:27 +02:00
transform_test.go main: switch to LLVM 10 2020-04-09 20:23:51 +02:00
util.go compiler: move OptimizeStringToBytes to transform package 2019-09-22 08:25:50 +02:00
wasm-abi.go transform: wasm-abi: create temporary allocas in the entry block 2020-01-28 19:29:09 +01:00
wasm-abi_test.go compiler: move wasm ABI workaround to transform package 2020-01-28 19:29:09 +01:00