-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix C compilation errors with closures and nested types (#1397)
## Summary Fix a bug with hook synthesis that led to C compiler errors when using some closure procedures or `ref`s of non-top-level `object` type. ## Details * `sighashes` now uses the symbol ID as the object representation for anonymous object/enum types and object/enum types not defined at the top-level * this means that `hashType(x) != hashType(y)` when `sameType(x, y) == false`, for object and enum types * as a consequence, unique hook procedures are used for `ref T` types that used the aforementioned types for `T` * RTTI, which is assigned to types based on type hashes, also uses unique instances per object type now Multiple same-shaped anonymous/non-top-level object types are *not* merged into a single one by the C code generator, which due to all sharing the same set of hook procedures, resulted in C compiler errors due to implicit conversions between incompatible pointer types. --------- Co-authored-by: Saem Ghani <[email protected]>
- Loading branch information
Showing
3 changed files
with
64 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
discard """ | ||
description: ''' | ||
Ensure that separate hooks are created for ``ref T`` types where T are non- | ||
top-level object types sharing the exact same name and shape | ||
''' | ||
targets: "c js vm" | ||
""" | ||
|
||
# XXX: this currently relies on the backend C compiler complaining. Eventually, | ||
# the test should inspect the MIR output and make sure two different | ||
# destroy hooks are used | ||
|
||
block: | ||
type Nested = object | ||
|
||
var a = (ref Nested)() | ||
|
||
block: | ||
type Nested = object | ||
|
||
var b = (ref Nested)() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
discard """ | ||
description: ''' | ||
Ensure that separate hooks are created for ``ref T`` types where T are non- | ||
top-level object types sharing the exact same name and shape | ||
''' | ||
targets: "c js vm" | ||
""" | ||
|
||
# XXX: this currently relies on the backend C compiler complaining. Eventually, | ||
# the test should inspect the MIR output and make sure two different | ||
# destroy hooks are used | ||
|
||
# for this test, both procedures must: | ||
# * share the same user-provided name | ||
# * create an anonymous environment object with the exact same shape and field | ||
# names | ||
|
||
proc outer(x: int) = | ||
var x = 1 | ||
proc inner() = | ||
x = 2 | ||
inner() | ||
|
||
proc outer(x: float) = | ||
var x = 1 | ||
proc inner() = | ||
x = 2 | ||
inner() | ||
|
||
outer(1) | ||
outer(1.0) |