Skip to content

Commit 4c87d28

Browse files
tests through records and fixes
1 parent 0478bc7 commit 4c87d28

2 files changed

Lines changed: 38 additions & 40 deletions

File tree

crates/d/src/lib.rs

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,7 +1280,7 @@ impl<'a> DInterfaceGenerator<'a> {
12801280
self.src.push_str("static ");
12811281
}
12821282
self.src.push_str(&format!(
1283-
"{} {}({}) @nogc nothrow {{\n",
1283+
"{} {}({}) @trusted nothrow {{\n",
12841284
d_sig.result,
12851285
d_sig.name,
12861286
d_sig
@@ -1353,7 +1353,7 @@ impl<'a> DInterfaceGenerator<'a> {
13531353
self.src.push_str("static ");
13541354
}
13551355
self.src.push_str(&format!(
1356-
"private extern(C) {} __import_{}({}) @nogc nothrow;\n",
1356+
"private extern(C) {} __import_{}({}) nothrow;\n",
13571357
match wasm_sig.results.len() {
13581358
0 => "void",
13591359
1 => wasm_type(wasm_sig.results[0]),
@@ -1727,11 +1727,9 @@ impl<'a> InterfaceGenerator<'a> for DInterfaceGenerator<'a> {
17271727

17281728
self.src.push_str(&format!(
17291729
"struct {escaped_name} {{
1730-
@nogc nothrow:
1731-
17321730
package({}) uint __handle = 0;
17331731
1734-
package({0}) this(uint handle) {{
1732+
package({0}) this(uint handle) @safe @nogc nothrow {{
17351733
__handle = handle;
17361734
}}
17371735
@@ -1782,8 +1780,9 @@ impl<'a> InterfaceGenerator<'a> for DInterfaceGenerator<'a> {
17821780
}
17831781
}
17841782

1785-
self.src
1786-
.push_str("\nvoid drop() {\n__import_drop(__handle);\n}\n");
1783+
self.src.push_str(
1784+
"\nvoid drop() @trusted @nogc nothrow {\n__import_drop(__handle);\n}\n",
1785+
);
17871786
self.src.push_str(&format!(
17881787
"@wasmImport!(\"{}\", \"[resource-drop]{}\")\n",
17891788
self.wasm_import_module.unwrap(),
@@ -1797,8 +1796,9 @@ impl<'a> InterfaceGenerator<'a> for DInterfaceGenerator<'a> {
17971796
.replace("-", "_"),
17981797
name.replace("-", "_")
17991798
));
1800-
self.src
1801-
.push_str("static private extern(C) void __import_drop(uint);\n\n");
1799+
self.src.push_str(
1800+
"static private extern(C) void __import_drop(uint) @nogc nothrow;\n\n",
1801+
);
18021802
self.src.push_str("alias witFree = drop;\n");
18031803

18041804
self.src.push_str(&format!(
@@ -1808,18 +1808,16 @@ impl<'a> InterfaceGenerator<'a> for DInterfaceGenerator<'a> {
18081808
alias borrow this;
18091809
18101810
struct Borrow {{
1811-
@nogc nothrow:
1812-
18131811
package({}) uint __handle = 0;
18141812
1815-
package({0}) this(uint handle) {{
1813+
package({0}) this(uint handle) @safe @nogc nothrow {{
18161814
__handle = handle;
18171815
}}
18181816
18191817
@disable this();
18201818
1821-
void witFree() {{}}
1822-
Borrow witClone() const {{ return Borrow(__handle); }}
1819+
void witFree() @safe @nogc nothrow {{}}
1820+
Borrow witClone() const @safe @nogc nothrow {{ return Borrow(__handle); }}
18231821
",
18241822
self.r#gen.root_pkg
18251823
));
@@ -1883,11 +1881,9 @@ impl<'a> InterfaceGenerator<'a> for DInterfaceGenerator<'a> {
18831881

18841882
self.src.push_str(&format!(
18851883
"struct {escaped_name} {{
1886-
@nogc nothrow:
1887-
18881884
package({}) uint __handle = 0;
18891885
1890-
package({0}) this(uint handle) {{
1886+
package({0}) this(uint handle) @safe @nogc nothrow {{
18911887
__handle = handle;
18921888
}}
18931889
@@ -1899,6 +1895,8 @@ impl<'a> InterfaceGenerator<'a> for DInterfaceGenerator<'a> {
18991895
self.src.push_str(&format!(
19001896
"
19011897
static {escaped_name} makeNew(T)(scope void delegate(out T) dg) if (is(T == struct)) {{
1898+
if (dg is null) return {escaped_name}.init;
1899+
19021900
auto ptr = cast(T*)malloc(T.sizeof);
19031901
if (ptr is null) return {escaped_name}.init;
19041902
@@ -1908,7 +1906,7 @@ impl<'a> InterfaceGenerator<'a> for DInterfaceGenerator<'a> {
19081906
",
19091907
));
19101908
self.src.push_str(&format!(
1911-
"@wasmImport!(\"{}\", \"[resource-new]{}\")\n",
1909+
"@wasmImport!(\"[export]{}\", \"[resource-new]{}\")\n",
19121910
self.wasm_import_module.unwrap(),
19131911
name
19141912
));
@@ -1924,9 +1922,9 @@ impl<'a> InterfaceGenerator<'a> for DInterfaceGenerator<'a> {
19241922
.push_str("static private extern(C) uint __import_makeNew(void*);\n\n");
19251923

19261924
self.src
1927-
.push_str("T* rep(T)() if (is(T == struct)) {\nreturn cast(T*)__import_rep(__handle);\n}\n");
1925+
.push_str("T* rep(T)() @nogc nothrow if (is(T == struct)) {\nreturn cast(T*)__import_rep(__handle);\n}\n");
19281926
self.src.push_str(&format!(
1929-
"@wasmImport!(\"{}\", \"[resource-rep]{}\")\n",
1927+
"@wasmImport!(\"[export]{}\", \"[resource-rep]{}\")\n",
19301928
self.wasm_import_module.unwrap(),
19311929
name
19321930
));
@@ -1941,10 +1939,11 @@ impl<'a> InterfaceGenerator<'a> for DInterfaceGenerator<'a> {
19411939
self.src
19421940
.push_str("static private extern(C) void __import_rep(uint);\n\n");
19431941

1944-
self.src
1945-
.push_str("void drop() {\n__import_drop(__handle);\n}\n");
1942+
self.src.push_str(
1943+
"void drop() @trusted @nogc nothrow {\n__import_drop(__handle);\n}\n",
1944+
);
19461945
self.src.push_str(&format!(
1947-
"@wasmImport!(\"{}\", \"[resource-drop]{}\")\n",
1946+
"@wasmImport!(\"[export]{}\", \"[resource-drop]{}\")\n",
19481947
self.wasm_import_module.unwrap(),
19491948
name
19501949
));
@@ -1956,28 +1955,27 @@ impl<'a> InterfaceGenerator<'a> for DInterfaceGenerator<'a> {
19561955
.replace("-", "_"),
19571956
name.replace("-", "_")
19581957
));
1959-
self.src
1960-
.push_str("static private extern(C) void __import_drop(uint);\n\n");
1958+
self.src.push_str(
1959+
"static private extern(C) void __import_drop(uint) @nogc nothrow;\n\n",
1960+
);
19611961
self.src.push_str("alias witFree = drop;\n");
19621962

19631963
self.src.push_str(&format!(
19641964
"// TODO: make RAII? disable copy for the own
1965-
Borrow borrow() => Borrow(__handle);
1965+
Borrow borrow() @safe @nogc nothrow => Borrow(__handle);
19661966
alias borrow this;
19671967
19681968
struct Borrow {{
1969-
@nogc nothrow:
1970-
19711969
package({}) uint __handle = 0;
19721970
1973-
package({0}) this(uint handle) {{
1971+
package({0}) this(uint handle) @safe @nogc nothrow {{
19741972
__handle = handle;
19751973
}}
19761974
19771975
@disable this();
19781976
1979-
void witFree() {{}}
1980-
Borrow witClone() const {{ return Borrow(__handle); }}
1977+
void witFree() @safe @nogc nothrow {{}}
1978+
Borrow witClone() const @safe @nogc nothrow {{ return Borrow(__handle); }}
19811979
19821980
",
19831981
self.r#gen.root_pkg
@@ -3106,9 +3104,9 @@ impl<'a, 'b> Bindgen for FunctionBindgen<'a, 'b> {
31063104
bool {is_some} = ({op0}) != 0;
31073105
if ({is_some}) {{
31083106
{some}
3109-
{resultname} = {type_name}.some({some_value});
3107+
{resultname} = {type_name}.makeSome({some_value});
31103108
}} else {{
3111-
{resultname} = {type_name}.none;
3109+
{resultname} = {type_name}.makeNone;
31123110
}}
31133111
"
31143112
));

crates/d/src/wit_common.d

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,11 @@ private:
145145
_value = value;
146146
}
147147
public:
148-
static inout(Option) some(inout T value) @safe @nogc nothrow {
148+
static inout(Option) makeSome(inout T value) @safe @nogc nothrow {
149149
return inout Option(true, value);
150150
}
151151

152-
static Option none() @safe @nogc nothrow {
152+
static Option makeNone() @safe @nogc nothrow {
153153
return Option(false, T.init);
154154
}
155155

@@ -169,11 +169,11 @@ public:
169169
}
170170

171171
auto some(T)(inout T value) @safe @nogc nothrow {
172-
return Option!T.some(value);
172+
return Option!T.makeSome(value);
173173
}
174174

175175
auto none(T)() @safe @nogc nothrow {
176-
return Option!T.none;
176+
return Option!T.makeNone;
177177
}
178178

179179
/// Based on Rust's Result
@@ -256,12 +256,12 @@ void witFree(T : Option!U, U)(scope ref T val) {
256256
T witClone(T : Option!U, U)(in T val) {
257257
if (val.isSome) {
258258
static if (!is(U == void)) {
259-
return T.some(val.unwrap.witClone);
259+
return T.makeSome(val.unwrap.witClone);
260260
} else {
261-
return T.some;
261+
return T.makeSome;
262262
}
263263
} else {
264-
return T.none;
264+
return T.makeNone;
265265
}
266266
}
267267

0 commit comments

Comments
 (0)