@@ -605,7 +605,7 @@ pub const RecordField = struct {
605
605
tree .pushStaticAtom ("field" );
606
606
tree .pushStringPair ("name" , ir .env .idents .getText (self .name ));
607
607
const attrs = tree .beginNode ();
608
- ir .store .getExpr (self .value ).pushToSExprTree (ir , tree );
608
+ ir .store .getExpr (self .value ).pushToSExprTree (ir , tree , self . value );
609
609
tree .endNode (begin , attrs );
610
610
}
611
611
};
@@ -633,7 +633,6 @@ pub const WhereClause = union(enum) {
633
633
/// Contains diagnostic information about what went wrong.
634
634
malformed : struct {
635
635
diagnostic : Diagnostic.Idx ,
636
- region : Region ,
637
636
},
638
637
639
638
pub const ModuleMethod = struct {
@@ -642,22 +641,21 @@ pub const WhereClause = union(enum) {
642
641
args : TypeAnno.Span , // Method argument types
643
642
ret_anno : TypeAnno.Idx , // Method return type
644
643
external_decl : ExternalDecl.Idx , // External declaration for module lookup
645
- region : Region ,
646
644
};
647
645
648
646
pub const ModuleAlias = struct {
649
647
var_name : Ident.Idx , // Type variable identifier (e.g., "elem")
650
648
alias_name : Ident.Idx , // Alias name without leading dot (e.g., "Sort")
651
649
external_decl : ExternalDecl.Idx , // External declaration for module lookup
652
- region : Region ,
653
650
};
654
651
655
- pub fn pushToSExprTree (self : * const @This (), ir : * const CIR , tree : * SExprTree ) void {
652
+ pub fn pushToSExprTree (self : * const @This (), ir : * const CIR , tree : * SExprTree , where_idx : WhereClause . Idx ) void {
656
653
switch (self .* ) {
657
654
.mod_method = > | mm | {
658
655
const begin = tree .beginNode ();
659
656
tree .pushStaticAtom ("method" );
660
- ir .appendRegionInfoToSExprTreeFromRegion (tree , mm .region );
657
+ const region = ir .store .getNodeRegion (@enumFromInt (@intFromEnum (where_idx )));
658
+ ir .appendRegionInfoToSExprTreeFromRegion (tree , region );
661
659
tree .pushStringPair ("module-of" , ir .env .idents .getText (mm .var_name ));
662
660
tree .pushStringPair ("ident" , ir .env .idents .getText (mm .method_name ));
663
661
const attrs = tree .beginNode ();
@@ -666,26 +664,28 @@ pub const WhereClause = union(enum) {
666
664
tree .pushStaticAtom ("args" );
667
665
const attrs2 = tree .beginNode ();
668
666
for (ir .store .sliceTypeAnnos (mm .args )) | arg_idx | {
669
- ir .store .getTypeAnno (arg_idx ).pushToSExprTree (ir , tree );
667
+ ir .store .getTypeAnno (arg_idx ).pushToSExprTree (ir , tree , arg_idx );
670
668
}
671
669
tree .endNode (args_begin , attrs2 );
672
670
673
- ir .store .getTypeAnno (mm .ret_anno ).pushToSExprTree (ir , tree );
671
+ ir .store .getTypeAnno (mm .ret_anno ).pushToSExprTree (ir , tree , mm . ret_anno );
674
672
tree .endNode (begin , attrs );
675
673
},
676
674
.mod_alias = > | ma | {
677
675
const begin = tree .beginNode ();
678
676
tree .pushStaticAtom ("alias" );
679
- ir .appendRegionInfoToSExprTreeFromRegion (tree , ma .region );
677
+ const region = ir .store .getNodeRegion (@enumFromInt (@intFromEnum (where_idx )));
678
+ ir .appendRegionInfoToSExprTreeFromRegion (tree , region );
680
679
tree .pushStringPair ("module-of" , ir .env .idents .getText (ma .var_name ));
681
680
tree .pushStringPair ("ident" , ir .env .idents .getText (ma .alias_name ));
682
681
const attrs = tree .beginNode ();
683
682
tree .endNode (begin , attrs );
684
683
},
685
- .malformed = > | m | {
684
+ .malformed = > | _ | {
686
685
const begin = tree .beginNode ();
687
686
tree .pushStaticAtom ("malformed" );
688
- ir .appendRegionInfoToSExprTreeFromRegion (tree , m .region );
687
+ const region = ir .store .getNodeRegion (@enumFromInt (@intFromEnum (where_idx )));
688
+ ir .appendRegionInfoToSExprTreeFromRegion (tree , region );
689
689
const attrs = tree .beginNode ();
690
690
tree .endNode (begin , attrs );
691
691
},
@@ -716,15 +716,15 @@ pub const PatternRecordField = struct {
716
716
pub const TypeHeader = struct {
717
717
name : Ident.Idx , // The type name (e.g., "Map", "List", "Dict")
718
718
args : TypeAnno.Span , // Type parameters (e.g., [a, b] for generic types)
719
- region : Region , // Source location of the entire header
720
719
721
720
pub const Idx = enum (u32 ) { _ };
722
721
pub const Span = struct { span : DataSpan };
723
722
724
- pub fn pushToSExprTree (self : * const @This (), ir : * const CIR , tree : * SExprTree ) void {
723
+ pub fn pushToSExprTree (self : * const @This (), ir : * const CIR , tree : * SExprTree , header_idx : TypeHeader . Idx ) void {
725
724
const begin = tree .beginNode ();
726
725
tree .pushStaticAtom ("ty-header" );
727
- ir .appendRegionInfoToSExprTreeFromRegion (tree , self .region );
726
+ const region = ir .store .getRegionAt (@enumFromInt (@intFromEnum (header_idx )));
727
+ ir .appendRegionInfoToSExprTreeFromRegion (tree , region );
728
728
tree .pushStringPair ("name" , ir .env .idents .getText (self .name ));
729
729
const attrs = tree .beginNode ();
730
730
@@ -733,7 +733,7 @@ pub const TypeHeader = struct {
733
733
tree .pushStaticAtom ("ty-args" );
734
734
const attrs2 = tree .beginNode ();
735
735
for (ir .store .sliceTypeAnnos (self .args )) | arg_idx | {
736
- ir .store .getTypeAnno (arg_idx ).pushToSExprTree (ir , tree );
736
+ ir .store .getTypeAnno (arg_idx ).pushToSExprTree (ir , tree , arg_idx );
737
737
}
738
738
tree .endNode (args_begin , attrs2 );
739
739
}
@@ -849,9 +849,7 @@ pub const IngestedFile = struct {
849
849
/// takes its value from an expression.
850
850
pub const Def = struct {
851
851
pattern : Pattern.Idx ,
852
- pattern_region : Region ,
853
852
expr : Expr.Idx ,
854
- expr_region : Region ,
855
853
// TODO:
856
854
// pattern_vars: SendMap<Symbol, Variable>,
857
855
annotation : ? Annotation.Idx ,
@@ -923,11 +921,11 @@ pub const Def = struct {
923
921
924
922
ir .store .getPattern (self .pattern ).pushToSExprTree (ir , tree , self .pattern );
925
923
926
- ir .store .getExpr (self .expr ).pushToSExprTree (ir , tree );
924
+ ir .store .getExpr (self .expr ).pushToSExprTree (ir , tree , self . expr );
927
925
928
926
if (self .annotation ) | anno_idx | {
929
927
const anno = ir .store .getAnnotation (anno_idx );
930
- anno .pushToSExprTree (ir , tree );
928
+ anno .pushToSExprTree (ir , tree , anno_idx );
931
929
}
932
930
933
931
tree .endNode (begin , attrs );
@@ -942,22 +940,21 @@ pub const Annotation = struct {
942
940
type_anno : TypeAnno.Idx ,
943
941
/// The canonical type signature as a type variable (for type inference)
944
942
signature : TypeVar ,
945
- /// Source region of the annotation
946
- region : Region ,
947
943
948
944
pub const Idx = enum (u32 ) { _ };
949
945
950
- pub fn pushToSExprTree (self : * const @This (), ir : * const CIR , tree : * SExprTree ) void {
946
+ pub fn pushToSExprTree (self : * const @This (), ir : * const CIR , tree : * SExprTree , anno_idx : Annotation . Idx ) void {
951
947
const begin = tree .beginNode ();
952
948
tree .pushStaticAtom ("annotation" );
953
- ir .appendRegionInfoToSExprTreeFromRegion (tree , self .region );
949
+ const region = ir .store .getRegionAt (@enumFromInt (@intFromEnum (anno_idx )));
950
+ ir .appendRegionInfoToSExprTreeFromRegion (tree , region );
954
951
const attrs = tree .beginNode ();
955
952
956
953
// Add the declared type annotation structure
957
954
const type_begin = tree .beginNode ();
958
955
tree .pushStaticAtom ("declared-type" );
959
956
const type_attrs = tree .beginNode ();
960
- ir .store .getTypeAnno (self .type_anno ).pushToSExprTree (ir , tree );
957
+ ir .store .getTypeAnno (self .type_anno ).pushToSExprTree (ir , tree , self . type_anno );
961
958
tree .endNode (type_begin , type_attrs );
962
959
963
960
tree .endNode (begin , attrs );
@@ -986,7 +983,7 @@ pub const ExternalDecl = struct {
986
983
/// Whether this is a value or type declaration
987
984
kind : enum { value , type },
988
985
989
- /// Region where this was referenced
986
+ /// Region where this external declaration was referenced
990
987
region : Region ,
991
988
992
989
pub const Idx = enum (u32 ) { _ };
@@ -1009,6 +1006,24 @@ pub const ExternalDecl = struct {
1009
1006
const attrs = tree .beginNode ();
1010
1007
tree .endNode (begin , attrs );
1011
1008
}
1009
+
1010
+ pub fn pushToSExprTreeWithRegion (self : * const @This (), ir : * const CIR , tree : * SExprTree , region : Region ) void {
1011
+ const begin = tree .beginNode ();
1012
+ tree .pushStaticAtom ("ext-decl" );
1013
+ ir .appendRegionInfoToSExprTreeFromRegion (tree , region );
1014
+
1015
+ // Add fully qualified name
1016
+ tree .pushStringPair ("ident" , ir .env .idents .getText (self .qualified_name ));
1017
+
1018
+ // Add kind
1019
+ switch (self .kind ) {
1020
+ .value = > tree .pushStringPair ("kind" , "value" ),
1021
+ .type = > tree .pushStringPair ("kind" , "type" ),
1022
+ }
1023
+
1024
+ const attrs = tree .beginNode ();
1025
+ tree .endNode (begin , attrs );
1026
+ }
1012
1027
};
1013
1028
1014
1029
/// Tracks type variables introduced during annotation canonicalization
@@ -1139,7 +1154,7 @@ pub fn pushToSExprTree(ir: *CIR, maybe_expr_idx: ?Expr.Idx, tree: *SExprTree, so
1139
1154
1140
1155
if (maybe_expr_idx ) | expr_idx | {
1141
1156
// Only output the given expression
1142
- ir .store .getExpr (expr_idx ).pushToSExprTree (ir , tree );
1157
+ ir .store .getExpr (expr_idx ).pushToSExprTree (ir , tree , expr_idx );
1143
1158
} else {
1144
1159
const root_begin = tree .beginNode ();
1145
1160
tree .pushStaticAtom ("can-ir" );
@@ -1158,7 +1173,7 @@ pub fn pushToSExprTree(ir: *CIR, maybe_expr_idx: ?Expr.Idx, tree: *SExprTree, so
1158
1173
}
1159
1174
1160
1175
for (statements_slice ) | stmt_idx | {
1161
- ir .store .getStatement (stmt_idx ).pushToSExprTree (ir , tree );
1176
+ ir .store .getStatement (stmt_idx ).pushToSExprTree (ir , tree , stmt_idx );
1162
1177
}
1163
1178
1164
1179
for (ir .external_decls .items ) | * external_decl | {
@@ -1305,7 +1320,9 @@ pub fn pushTypesToSExprTree(ir: *CIR, maybe_expr_idx: ?Expr.Idx, tree: *SExprTre
1305
1320
const patt_begin = tree .beginNode ();
1306
1321
tree .pushStaticAtom ("patt" );
1307
1322
1308
- ir .appendRegionInfoToSExprTree (tree , def_idx );
1323
+ // Get the pattern region instead of the whole def region
1324
+ const pattern_region = ir .store .getPatternRegion (def .pattern );
1325
+ ir .appendRegionInfoToSExprTreeFromRegion (tree , pattern_region );
1309
1326
1310
1327
// Get the type variable for this definition
1311
1328
const def_var = ir .idxToTypeVar (& ir .env .types , def_idx ) catch | err | exitOnOom (err );
@@ -1367,7 +1384,8 @@ pub fn pushTypesToSExprTree(ir: *CIR, maybe_expr_idx: ?Expr.Idx, tree: *SExprTre
1367
1384
1368
1385
const stmt_node_begin = tree .beginNode ();
1369
1386
tree .pushStaticAtom ("alias" );
1370
- ir .appendRegionInfoToSExprTreeFromRegion (tree , alias .region );
1387
+ const alias_region = ir .store .getStatementRegion (stmt_idx );
1388
+ ir .appendRegionInfoToSExprTreeFromRegion (tree , alias_region );
1371
1389
1372
1390
// Clear the buffer and write the type
1373
1391
type_string_buf .clearRetainingCapacity ();
@@ -1376,7 +1394,7 @@ pub fn pushTypesToSExprTree(ir: *CIR, maybe_expr_idx: ?Expr.Idx, tree: *SExprTre
1376
1394
const stmt_node_attrs = tree .beginNode ();
1377
1395
1378
1396
const header = ir .store .getTypeHeader (alias .header );
1379
- header .pushToSExprTree (ir , tree );
1397
+ header .pushToSExprTree (ir , tree , alias . header );
1380
1398
1381
1399
tree .endNode (stmt_node_begin , stmt_node_attrs );
1382
1400
},
@@ -1385,7 +1403,8 @@ pub fn pushTypesToSExprTree(ir: *CIR, maybe_expr_idx: ?Expr.Idx, tree: *SExprTre
1385
1403
1386
1404
const stmt_node_begin = tree .beginNode ();
1387
1405
tree .pushStaticAtom ("nominal" );
1388
- ir .appendRegionInfoToSExprTreeFromRegion (tree , nominal .region );
1406
+ const nominal_region = ir .store .getStatementRegion (stmt_idx );
1407
+ ir .appendRegionInfoToSExprTreeFromRegion (tree , nominal_region );
1389
1408
1390
1409
// Clear the buffer and write the type
1391
1410
type_string_buf .clearRetainingCapacity ();
@@ -1395,7 +1414,7 @@ pub fn pushTypesToSExprTree(ir: *CIR, maybe_expr_idx: ?Expr.Idx, tree: *SExprTre
1395
1414
const stmt_node_attrs = tree .beginNode ();
1396
1415
1397
1416
const header = ir .store .getTypeHeader (nominal .header );
1398
- header .pushToSExprTree (ir , tree );
1417
+ header .pushToSExprTree (ir , tree , nominal . header );
1399
1418
1400
1419
tree .endNode (stmt_node_begin , stmt_node_attrs );
1401
1420
},
@@ -1423,7 +1442,10 @@ pub fn pushTypesToSExprTree(ir: *CIR, maybe_expr_idx: ?Expr.Idx, tree: *SExprTre
1423
1442
1424
1443
const expr_node_begin = tree .beginNode ();
1425
1444
tree .pushStaticAtom ("expr" );
1426
- ir .appendRegionInfoToSExprTreeFromRegion (tree , def .expr_region );
1445
+
1446
+ // Add region info for the expression
1447
+ const expr_region = ir .store .getExprRegion (def .expr );
1448
+ ir .appendRegionInfoToSExprTreeFromRegion (tree , expr_region );
1427
1449
1428
1450
if (@intFromEnum (expr_var ) > ir .env .types .slots .backing .items .len ) {
1429
1451
const unknown_begin = tree .beginNode ();
0 commit comments