Skip to content

Commit

Permalink
fix(rivet/resolver): fix file abi checking
Browse files Browse the repository at this point in the history
  • Loading branch information
StunxFS committed Dec 3, 2023
1 parent d9a4137 commit 05ee473
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 19 deletions.
File renamed without changes.
File renamed without changes.
12 changes: 0 additions & 12 deletions lib/core/src/errors.c.ri

This file was deleted.

10 changes: 9 additions & 1 deletion lib/core/src/errors.ri
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -117,4 +126,3 @@ pub struct ValueOutOfRangeError < Throwable {
return self.msg;
}
}

File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 4 additions & 3 deletions lib/rivet/src/resolver/exprs.ri
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
8 changes: 5 additions & 3 deletions lib/rivet/src/resolver/mod.ri
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand All @@ -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;
}
}

Expand Down

0 comments on commit 05ee473

Please sign in to comment.