From 05ee4735906887e4501b9adafeec6a681b3117dc Mon Sep 17 00:00:00 2001 From: StunxFS Date: Sun, 3 Dec 2023 15:25:42 -0400 Subject: [PATCH] fix(rivet/resolver): fix file abi checking --- lib/core/src/{TestRunner.c.ri => TestRunner.ri} | 0 lib/core/src/{Vector.c.ri => Vector.ri} | 0 lib/core/src/errors.c.ri | 12 ------------ lib/core/src/errors.ri | 10 +++++++++- lib/core/src/{ptr.c.ri => ptr.ri} | 0 lib/core/src/{rune.c.ri => rune.ri} | 0 lib/core/src/{utils.c.ri => utils.ri} | 0 lib/rivet/src/resolver/exprs.ri | 7 ++++--- lib/rivet/src/resolver/mod.ri | 8 +++++--- 9 files changed, 18 insertions(+), 19 deletions(-) rename lib/core/src/{TestRunner.c.ri => TestRunner.ri} (100%) rename lib/core/src/{Vector.c.ri => Vector.ri} (100%) delete mode 100644 lib/core/src/errors.c.ri rename lib/core/src/{ptr.c.ri => ptr.ri} (100%) rename lib/core/src/{rune.c.ri => rune.ri} (100%) rename lib/core/src/{utils.c.ri => utils.ri} (100%) diff --git a/lib/core/src/TestRunner.c.ri b/lib/core/src/TestRunner.ri similarity index 100% rename from lib/core/src/TestRunner.c.ri rename to lib/core/src/TestRunner.ri diff --git a/lib/core/src/Vector.c.ri b/lib/core/src/Vector.ri similarity index 100% rename from lib/core/src/Vector.c.ri rename to lib/core/src/Vector.ri diff --git a/lib/core/src/errors.c.ri b/lib/core/src/errors.c.ri deleted file mode 100644 index 0e1c77fcc..000000000 --- a/lib/core/src/errors.c.ri +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (C) 2023 The Rivet Developers. All rights reserved. -// Use of this source code is governed by an MIT license that can -// be found in the LICENSE file. - -import c; - -pub alias ErrnoError := c.ErrnoError; - -// FIXME: pub alias last_errno_error := c.last_errno_error; -pub func last_errno_error() -> c.ErrnoError { - return c.last_errno_error(); -} diff --git a/lib/core/src/errors.ri b/lib/core/src/errors.ri index f38579bc6..5e156ad8b 100644 --- a/lib/core/src/errors.ri +++ b/lib/core/src/errors.ri @@ -2,6 +2,15 @@ // Use of this source code is governed by an MIT license that can // be found in the LICENSE file. +import c; + +pub alias ErrnoError := c.ErrnoError; + +// FIXME: pub alias last_errno_error := c.last_errno_error; +pub func last_errno_error() -> c.ErrnoError { + return c.last_errno_error(); +} + var returnTrace := ReturnTrace(); /// This trait is used for errors throwed with result types (!T). @@ -117,4 +126,3 @@ pub struct ValueOutOfRangeError < Throwable { return self.msg; } } - diff --git a/lib/core/src/ptr.c.ri b/lib/core/src/ptr.ri similarity index 100% rename from lib/core/src/ptr.c.ri rename to lib/core/src/ptr.ri diff --git a/lib/core/src/rune.c.ri b/lib/core/src/rune.ri similarity index 100% rename from lib/core/src/rune.c.ri rename to lib/core/src/rune.ri diff --git a/lib/core/src/utils.c.ri b/lib/core/src/utils.ri similarity index 100% rename from lib/core/src/utils.c.ri rename to lib/core/src/utils.ri diff --git a/lib/rivet/src/resolver/exprs.ri b/lib/rivet/src/resolver/exprs.ri index 7e8dda371..3c484c04b 100644 --- a/lib/rivet/src/resolver/exprs.ri +++ b/lib/rivet/src/resolver/exprs.ri @@ -358,17 +358,18 @@ extend Resolver { func check_symbol_abi(mut self, sym: ast.Sym, pos: token.Pos) { if sym.abi != .Rivet { - if self.source_file_abi != sym.abi { + if self.source_file_abi == sym.abi { + self.different_abi_usage_count += 1; + } else { mut warn := report.warn_builder( "using a symbol whose ABI is different from that of the current file", pos ); warn.add_note("`{}` is declared as `extern ({})`", sym.name, sym.abi); warn.add_help( - "consider adding `.{}.` extension to current filename", sym.abi.lower() + "consider adding `.{}.ri` extension to current filename", sym.abi.lower() ); warn.emit(); } - self.different_abi_usage_count += 1; } } } diff --git a/lib/rivet/src/resolver/mod.ri b/lib/rivet/src/resolver/mod.ri index 6e3981b5f..ea37bd2c6 100644 --- a/lib/rivet/src/resolver/mod.ri +++ b/lib/rivet/src/resolver/mod.ri @@ -26,7 +26,7 @@ pub struct Resolver { mut self_sym_is_set: bool; mut source_file: ast.SourceFile; - mut source_file_abi: ast.ABI := .Rivet; + mut source_file_abi: ast.ABI; mut different_abi_usage_count: uint; pub func resolve_files(mut self, source_files: []ast.SourceFile) { @@ -38,10 +38,10 @@ pub struct Resolver { Prelude("Throwable", self.table.throwable_sym) ]; for sf in source_files { - self.source_file_abi = .Rivet; self.sym = sf.mod; self.source_file = sf; self.detect_source_file_abi(); + self.different_abi_usage_count = 0; self.resolve_decls(self.source_file.decls); if self.source_file_abi == .Rivet and self.different_abi_usage_count > 0 { report.warn("filename requires ABI specification", sf.pos); @@ -53,8 +53,10 @@ pub struct Resolver { func detect_source_file_abi(mut self) { filename := Path.file_name(self.source_file.path); - if filename.contains(".c.") { + if filename.ends_with(".c.ri") { self.source_file_abi = .C; + } else { + self.source_file_abi = .Rivet; } }