Bug 23127 – @safe inference seems to depend on semantic analysis order

Status
NEW
Severity
blocker
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-05-19T16:35:33Z
Last change time
2024-12-13T19:22:59Z
Keywords
industry
Assigned to
No Owner
Creator
kinke
Moved to GitHub: dmd#20109 →

Attachments

IDFilenameSummaryContent-TypeSize
1853source_final.tar.xz4 source modulesapplication/x-xz892

Comments

Comment #0 by kinke — 2022-05-19T16:35:33Z
Created attachment 1853 4 source modules The attached archive contains 4 dustmited modules. With DMD v2.100.0, all 4 modules can be individually compiled just fine. With `-allinst` however, compiling `variant.d` (alone) fails with: ----- rbtree.d(36): Error: `@safe` function `rbtree.RedBlackTree!(Pair, lessPairKeys).RedBlackTree.toHash` cannot call `@system` function `rbtree.RBRange!(RBNode!(Pair)*).RBRange.popFront` rbtree.d(22): `rbtree.RBRange!(RBNode!(Pair)*).RBRange.popFront` is declared here statictypes.d(12): Error: template instance `rbtree.RedBlackTree!(Pair, lessPairKeys)` error instantiating statictypes.d(15): instantiated from here: `Map!(string, SType)` ----- The 3 other modules compile fine with `-allinst` too. Prepending another root module works: `dmd -o- -allinst statictypes.d variant.d`. Swapping the root modules order makes it fail again: `dmd -o- -allinst variant.d statictypes.d`
Comment #1 by maxhaton — 2022-05-19T21:34:18Z
I'm going to have a crack at this tonight.
Comment #2 by maxhaton — 2022-05-20T01:27:42Z
Some printf debugging: Context: popFront exp: sym/rbtree.d(22):(*this._begin).next() Data about f: next sym/rbtree.d(9) (null) next has type RBNode!(Pair)*() setUnsafe: next setUnsafe: In progress sc.flag & compile: not setUnsafe: sym/rbtree.d(9) popFront setUnsafe: In progress FuncDeclaration::semantic3(function 'next', sc = 0x7f7eb91f03d0) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Semantic3 is on next run *after* its first use.
Comment #3 by maxhaton — 2022-05-20T02:23:38Z
RBNode has it's AggregateDecl semantic3 done far far too late. I've checked for plain memory corruption, I think this is something trying to be clever and failing (as per usual).
Comment #4 by kinke — 2022-07-21T13:31:39Z
Comment #5 by johanengelen — 2022-07-23T10:17:26Z
Comment #6 by robert.schadek — 2024-12-13T19:22:59Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20109 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB