Commit Graph

6 Commits

Author SHA1 Message Date
Kuba (Brecka) Mracek
f04efab969 Fix typo in SectionTopLevel.swift 2025-11-07 12:48:04 -08:00
Kuba (Brecka) Mracek
09146b1714 Relax expectations in SectionTopLevel.swift for 32-bit and arm64e 2025-11-07 10:48:50 -08:00
Kuba (Brecka) Mracek
eaa3f8a5b0 Annotate SectionTopLevel.swift with REQUIRES: swift_feature_ParserASTGen 2025-11-03 21:11:05 -08:00
Kuba Mracek
ee623f8d59 Add @section/@const handling of globals to ASTGen too 2025-11-03 13:47:51 -08:00
Kuba Mracek
5f81c1b793 SE-0492: Handle top-level @section-annotated globals
Currently, normal globals are represented as a PatternBindingDecl and a VarDecl in the AST, directly under the SourceFile:

```
// var variable_name = 42, compiled with -parse-as-library
(source_file ...
  (pattern_binding_decl ...
    (pattern_entry ...
      (pattern_named ... "variable_name") ...
  (var_decl "variable_name" ...
```

Top-level globals are represented more like local variables, under a TopLevelCodeDecl. Note that the VarDecl is still at the file scope. In SILGen, this case has some special handling to use the a storage of a global variable, and to avoid cleanups (see `emitInitializationForVarDecl`). Effectively, this means the globals are initialized inside the `main` function.

```
// var variable_name = 42, compiled without -parse-as-library
(source_file ...
  (top_level_code_decl ...
    (brace_stmt ...
      (pattern_binding_decl ...
        (pattern_named ... "variable_name") ...
  (var_decl "variable_name" ... top_level_global
```

SE-0492 needs top-level globals that have a `@section` annotation to behave like a normal global -- initialization must happen statically, and not in `main`. This PR changes the parsing of those globals to match normal globals, without the TopLevelCodeDecl wrapper. SILGen and IRGen then handles them correctly.
2025-10-25 10:48:44 -07:00
Kuba Mracek
00fc1fad96 Add an XFAIL-ing test for top-level mode @section globals 2025-10-23 08:37:39 -07:00