Skip to content

Commit 565e37e

Browse files
committed
fix(rivet+rivetc): avoid autoloading the core module when it is being compiled
1 parent 704b808 commit 565e37e

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

lib/rivet/src/Builder.ri

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ pub struct Builder {
3838
pub func run(mut self) -> ! {
3939
self.make_rivet_directory()!;
4040

41-
_ = self.load_module("core", "core", "", token.no_pos)!;
41+
// if we are compiling the `core` module, avoid autoloading it
42+
if self.env.prefs.mod_name != "core" {
43+
_ = self.load_module("core", "core", "", token.no_pos)!;
44+
}
45+
4246
self.load_root_module()!;
4347
self.import_modules()!;
4448

lib/rivet/src/parser/decls.ri

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// Copyright (C) 2023-present Jose Mendoza - All rights reserved. Use of this
2-
// source code is governed by an MIT license that can be found in the LICENSE
1+
// Copyright (C) 2023-present Jose Mendoza - All rights reserved. Use of this
2+
// source code is governed by an MIT license that can be found in the LICENSE
33
// file.
44

55
import std/strings;
@@ -658,6 +658,7 @@ extend Parser {
658658
}
659659
self.close_scope();
660660
self.inside_func = false;
661+
is_main := self.mod_sym.is_root && self.mod_sym.name != "core" && name == "main";
661662
return .Func(
662663
docs: docs,
663664
abi: abi,
@@ -668,7 +669,7 @@ extend Parser {
668669
is_variadic: is_variadic,
669670
is_method: is_method,
670671
is_special_method: is_special_method,
671-
is_main: self.mod_sym.is_root && name == "main",
672+
is_main: is_main,
672673
is_operator: is_operator,
673674
name: name,
674675
args: args,

rivetc/src/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,13 @@ def import_graph(self):
124124
return g
125125

126126
def run(self):
127-
self.parsed_files += self.load_module("core", "core", "", token.NO_POS)
127+
# if we are compiling the `core` module, avoid autoloading it
128+
if self.prefs.mod_name != "core":
129+
self.parsed_files += self.load_module("core", "core", "", token.NO_POS)
130+
128131
self.load_root_module()
129132
self.import_modules()
133+
130134
if not self.prefs.check_syntax:
131135
self.vlog("registering symbols...")
132136
self.register.walk_files(self.source_files)

rivetc/src/parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ def parse_func_decl(
550550
doc_comment, attributes, is_public, self.inside_extern, is_unsafe,
551551
name, pos, args, ret_typ, stmts, sc, has_body, is_method,
552552
self_is_mut, self_is_ptr, has_named_args, self.mod_sym.is_root
553-
and name == "main", is_variadic, abi
553+
and self.mod_sym.name != "core" and name == "main", is_variadic, abi
554554
)
555555

556556
# ---- statements --------------------------

0 commit comments

Comments
 (0)