Skip to content

Commit 66dc33f

Browse files
committed
Align runnable lowering with v0.5 signatures
1 parent 6a758d9 commit 66dc33f

6 files changed

Lines changed: 73 additions & 34 deletions

File tree

core/fs/file.rssi

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ pub fn File.open_read(path: read Path) -> fresh File
66

77
pub fn File.open_write(path: read Path) -> fresh File
88

9-
pub fn File.read_all(file: mut File) -> fresh Bytes
10-
11-
pub fn File.write(file: mut File, data: read Bytes) -> Unit
9+
pub fn File.read_all(file: mut File) -> Result<fresh Bytes, FileError>
1210

11+
pub fn File.write(file: mut File, data: read Bytes) -> Result<Unit, FileError>

core/image/image.rssi

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
struct Image
22

3-
pub fn Image.load(path: read Path) -> fresh Image
3+
pub fn Image.load(path: read Path) -> Result<fresh Image, ImageError>
44

55
pub fn Image.resize(image: mut Image, width: Int, height: Int) -> Unit
66

7-
pub fn Image.save(image: read Image, path: read Path) -> Unit
7+
pub fn Image.save(image: read Image, path: read Path) -> Result<Unit, ImageError>
88

99
pub fn Image.inspect(image: read Image) -> Unit
10-

src/hir.rs

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,7 +1541,7 @@ fn builtin_signatures() -> Vec<FunctionSig> {
15411541
"Image",
15421542
"load",
15431543
&[param("path", ParamEffect::Read, "Path")],
1544-
Some("Image"),
1544+
Some("Result<Image, ImageError>"),
15451545
true,
15461546
&[],
15471547
),
@@ -1580,7 +1580,7 @@ fn builtin_signatures() -> Vec<FunctionSig> {
15801580
param("image", ParamEffect::Read, "Image"),
15811581
param("path", ParamEffect::Read, "Path"),
15821582
],
1583-
Some("Unit"),
1583+
Some("Result<Unit, ImageError>"),
15841584
false,
15851585
&[],
15861586
),
@@ -1631,7 +1631,7 @@ fn builtin_signatures() -> Vec<FunctionSig> {
16311631
"File",
16321632
"read_all",
16331633
&[param("file", ParamEffect::Mut, "File")],
1634-
Some("Bytes"),
1634+
Some("Result<Bytes, FileError>"),
16351635
true,
16361636
&[],
16371637
),
@@ -1642,7 +1642,7 @@ fn builtin_signatures() -> Vec<FunctionSig> {
16421642
param("file", ParamEffect::Mut, "File"),
16431643
param("data", ParamEffect::Read, "Bytes"),
16441644
],
1645-
Some("Unit"),
1645+
Some("Result<Unit, FileError>"),
16461646
false,
16471647
&[],
16481648
),
@@ -1697,7 +1697,7 @@ fn builtin_signatures() -> Vec<FunctionSig> {
16971697
"Json",
16981698
"parse",
16991699
&[param("text", ParamEffect::Read, "String")],
1700-
Some("JsonValue"),
1700+
Some("Result<JsonValue, JsonError>"),
17011701
true,
17021702
&[],
17031703
),
@@ -1708,8 +1708,8 @@ fn builtin_signatures() -> Vec<FunctionSig> {
17081708
param("value", ParamEffect::Read, "JsonValue"),
17091709
param("name", ParamEffect::Read, "String"),
17101710
],
1711-
Some("String"),
1712-
true,
1711+
Some("Result<String, JsonError>"),
1712+
false,
17131713
&[],
17141714
),
17151715
builtin(
@@ -1719,15 +1719,15 @@ fn builtin_signatures() -> Vec<FunctionSig> {
17191719
param("file", ParamEffect::Mut, "File"),
17201720
param("buffer", ParamEffect::Mut, "RowBuffer"),
17211721
],
1722-
Some("Unit"),
1722+
Some("Result<Unit, CsvError>"),
17231723
false,
17241724
&[],
17251725
),
17261726
builtin(
17271727
"Csv",
17281728
"parse_row",
17291729
&[param("buffer", ParamEffect::Read, "RowBuffer")],
1730-
Some("Row"),
1730+
Some("Result<Row, CsvError>"),
17311731
true,
17321732
&[],
17331733
),
@@ -1789,7 +1789,7 @@ fn builtin_signatures() -> Vec<FunctionSig> {
17891789
param("conn", ParamEffect::Mut, "DbConnection"),
17901790
param("sql", ParamEffect::Read, "String"),
17911791
],
1792-
None,
1792+
Some("Result<Unit, DbError>"),
17931793
false,
17941794
&[],
17951795
),
@@ -1805,7 +1805,7 @@ fn builtin_signatures() -> Vec<FunctionSig> {
18051805
"RuleLoader",
18061806
"load_rules",
18071807
&[param("path", ParamEffect::Read, "Path")],
1808-
Some("List"),
1808+
Some("Result<List<Rule>, ConfigError>"),
18091809
true,
18101810
&[],
18111811
),
@@ -1987,7 +1987,10 @@ fn cache_put(cache: mut Cache, value: read Image) -> Unit
19871987
let load = hir
19881988
.resolve_function(Some("Image"), "load")
19891989
.expect("builtin signature exists");
1990-
assert_eq!(load.return_type.as_deref(), Some("Image"));
1990+
assert_eq!(
1991+
load.return_type.as_deref(),
1992+
Some("Result<Image, ImageError>")
1993+
);
19911994
}
19921995

19931996
#[test]
@@ -2011,8 +2014,8 @@ fn Image(path: read Path) -> Image {
20112014

20122015
assert_eq!(duplicate.kind, DuplicateSymbolKind::Constructor);
20132016
assert_eq!(duplicate.name, "Image");
2014-
assert_eq!(duplicate.first_span.line, 4);
2015-
assert_eq!(duplicate.duplicate_span.line, 8);
2017+
assert_eq!(duplicate.first_span.line, 3);
2018+
assert_eq!(duplicate.duplicate_span.line, 7);
20162019
}
20172020

20182021
#[test]
@@ -2034,8 +2037,8 @@ struct Response {
20342037

20352038
assert_eq!(duplicate.kind, DuplicateSymbolKind::Field);
20362039
assert_eq!(duplicate.name, "Response.status");
2037-
assert_eq!(duplicate.first_span.line, 5);
2038-
assert_eq!(duplicate.duplicate_span.line, 6);
2040+
assert_eq!(duplicate.first_span.line, 4);
2041+
assert_eq!(duplicate.duplicate_span.line, 5);
20392042
}
20402043

20412044
#[test]
@@ -2124,7 +2127,7 @@ fn render(body: read String) -> Result<fresh Response, HttpError> {
21242127
features: local
21252128
21262129
fn load(path: read Path) -> Unit {
2127-
local image = Image.load(path: read path)
2130+
local image = Image.load(path: read path)?
21282131
}
21292132
"#;
21302133

@@ -2309,7 +2312,7 @@ struct Config {
23092312
}
23102313
23112314
fn update(cache: mut ImageCache, config: mut Config, path: read Path) -> Unit {
2312-
local image = Image.load(path: read path)
2315+
local image = Image.load(path: read path)?
23132316
ImageCache.store(cache: mut cache, image: read image)
23142317
List.consume(list: take config.rules)
23152318
}
@@ -2324,7 +2327,7 @@ fn update(cache: mut ImageCache, config: mut Config, path: read Path) -> Unit {
23242327
let HirStmt::Let {
23252328
kind: HirBindingKind::LocalLet,
23262329
name,
2327-
value: Some(HirExpr::Call { type_name, .. }),
2330+
value: Some(HirExpr::Try { type_name, .. }),
23282331
type_name: Some(binding_type),
23292332
..
23302333
} = &block.statements[0]

src/review.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ fn review_map_region_draft(
455455
reasons.push("ResourcePool usage".to_string());
456456
}
457457

458+
let had_review_reason = !reasons.is_empty();
458459
let classification = if !facts.unresolved_calls.is_empty() {
459460
let calls = facts
460461
.unresolved_calls
@@ -463,7 +464,11 @@ fn review_map_region_draft(
463464
.collect::<Vec<_>>()
464465
.join(", ");
465466
reasons.push(format!("unresolved call(s): {calls}"));
466-
ReviewMapClassification::Unknown
467+
if had_review_reason {
468+
ReviewMapClassification::ReviewRequired
469+
} else {
470+
ReviewMapClassification::Unknown
471+
}
467472
} else if reasons.is_empty() {
468473
reasons.push("private pure helper with no retention or resource boundary".to_string());
469474
ReviewMapClassification::Foldable

src/rust_lower.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,12 +320,14 @@ impl<'a> RustLowerer<'a> {
320320
}
321321
out.push('\n');
322322

323-
for item in &self.program.items {
323+
for (index, item) in self.program.items.iter().enumerate() {
324324
match item {
325325
Item::Type(ty) => self.lower_type_decl(ty, &mut out),
326326
Item::Function(function) => self.lower_function(function, &mut out),
327327
}
328-
out.push('\n');
328+
if index + 1 < self.program.items.len() {
329+
out.push('\n');
330+
}
329331
}
330332

331333
LoweredRust {
@@ -398,9 +400,10 @@ impl<'a> RustLowerer<'a> {
398400
fn lower_function(&mut self, function: &FunctionDecl, out: &mut String) {
399401
self.record_source_marker(out, 0, "function", &function.span);
400402
let async_prefix = if function.is_async { "async " } else { "" };
403+
let is_public = function.is_public || is_runnable_main(function);
401404
out.push_str(&format!(
402405
"{}{}fn {}{}(",
403-
visibility(function.is_public),
406+
visibility(is_public),
404407
async_prefix,
405408
rust_ident(&function.name),
406409
lower_generic_params(&function.type_params)
@@ -1095,14 +1098,30 @@ fn rust_ident(name: &str) -> String {
10951098
fn cargo_package_name(name: &str) -> String {
10961099
let mut out = String::new();
10971100
let mut previous_was_dash = false;
1101+
let mut previous_was_lower_or_digit = false;
10981102

10991103
for character in name.chars() {
11001104
if character.is_ascii_alphanumeric() {
1105+
if character.is_ascii_uppercase()
1106+
&& previous_was_lower_or_digit
1107+
&& !previous_was_dash
1108+
&& !out.is_empty()
1109+
{
1110+
out.push('-');
1111+
}
11011112
out.push(character.to_ascii_lowercase());
11021113
previous_was_dash = false;
1103-
} else if matches!(character, '-' | '_' | '.') && !out.is_empty() && !previous_was_dash {
1114+
previous_was_lower_or_digit =
1115+
character.is_ascii_lowercase() || character.is_ascii_digit();
1116+
} else if (character.is_ascii_whitespace() || matches!(character, '-' | '_' | '.'))
1117+
&& !out.is_empty()
1118+
&& !previous_was_dash
1119+
{
11041120
out.push('-');
11051121
previous_was_dash = true;
1122+
previous_was_lower_or_digit = false;
1123+
} else {
1124+
previous_was_lower_or_digit = false;
11061125
}
11071126
}
11081127

src/syntax/parser.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,14 @@ impl Parser<'_> {
9090
self.index = close + 1;
9191
parse_fields(self.tokens, open + 1, close)
9292
} else {
93-
let end = declaration_line_end(self.tokens, self.index);
94-
self.index = end;
93+
if self
94+
.tokens
95+
.get(self.index)
96+
.is_some_and(|token| token.span.line == span.line)
97+
{
98+
let end = declaration_line_end(self.tokens, self.index);
99+
self.index = end;
100+
}
95101
Vec::new()
96102
};
97103

@@ -121,7 +127,7 @@ impl Parser<'_> {
121127
return None;
122128
}
123129
self.index += 1;
124-
let name = self.take_ident_name()?;
130+
let name = self.take_function_name()?;
125131
let type_params = self.parse_generic_params();
126132

127133
let mut params = Vec::new();
@@ -639,7 +645,15 @@ fn parse_expr(tokens: &[Token], start: usize, end: usize) -> Option<Expr> {
639645

640646
if tokens[start].symbol("|") && tokens.get(start + 1).is_some_and(|token| token.symbol("|")) {
641647
let Some(open) = (start + 2..end).find(|index| tokens[*index].symbol("{")) else {
642-
return Some(Expr::Unknown(tokens[start].span.clone()));
648+
let value = parse_expr(tokens, start + 2, end)
649+
.unwrap_or_else(|| Expr::Unknown(tokens[start].span.clone()));
650+
return Some(Expr::Closure {
651+
body: Block {
652+
statements: vec![Stmt::Expr(value)],
653+
span: tokens[start].span.clone(),
654+
},
655+
span: tokens[start].span.clone(),
656+
});
643657
};
644658
let close = find_matching(tokens, open, "{", "}").unwrap_or(open);
645659
return Some(Expr::Closure {

0 commit comments

Comments
 (0)