Repository navigation
Five defects the c-interop example exposed, rebased onto main; CStr.to_owned; the old example removed until the SQLite facade (D51 §66) - #1234
Merged
Conversation
… CStr.from_ptr, §4.9 fall-through, @[c_export] over a declared prototype, parameter shadowing (#1232) * A str is lent to a const char * in a raw call too (§16.3c, D47) The blessed sentence has no condition on the function's other parameters. SemaDiag.try_ci_coercion gated lending on ci_raw_syms, so any function with a raw-pointer parameter (sqlite3_open, sqlite3_prepare_v2, strtol) refused a str for its text input and sent the caller to c"...".ptr and CString. I added that gate in #1222; it was never part of the ruling. * CStr.from_ptr and CStr.to_str: read the C string C handed back (§16.1) The spec spells CStr.from_ptr(p).to_str(); CStr had only len() and ptr(), and the stdlib read C strings through with_str_from_cstr, which a program may not name. sqlite3_errmsg and sqlite3_column_text left every user writing an unsafe byte loop. from_ptr is unsafe (the caller vouches for the pointer); to_str is an owned copy. * A Result[Unit, E] body that falls through after an early return Err is Ok(()) (§4.9) The spec's own validate example was 'missing return': SemaCheck flagged any Unit-typed body that holds an explicit value return and can fall through, with no exemption for Result[Unit, E], where falling through is the Ok(()) §4.9 promises. The closure site waits on #1230. * @[c_export] defines the prototype a c_imported header declares A C library that calls back into With declares the callback in its header. The c_imported prototype and the With definition became two LLVM functions of one name: the body was renamed name.1 and the prototype the C code calls stayed undefined at link. The body now goes into the existing declaration, as it already does for runtime names, so every call site that holds the prototype holds the definition. * A parameter or local shadows another module's global of its name A private top-level `let ptr` broke every imported function that has a `ptr` parameter: "symbol 'ptr' is not visible from this module", for a free function, a type-level function and a method alike. check_ident (SemaCheck.w) found the parameter through scope_lookup, then ran the visibility checks through binding_decl_node / global_value_decl_kind, which look the NAME up again and found the other module's global. Found by an lldb breakpoint on emit_private_symbol_error. A binding made below the module-level scope is a local, and visibility does not apply to it. Exposed by CStr.from_ptr(ptr: ...), which put a `ptr` parameter in the prelude and collided with behav_annotated_top_level_runtime_init.w's global. --------- Co-authored-by: Eric Hartford <[email protected]>
…t it does (D51 §41) The ruling reserves to_str() for the validating conversion and names the owned copy to_owned(). Renamed before the name lands.
The old example did not compile, its test tested strlen, its README described a program that no longer existed, and a compiled binary was checked in; the three source files went with #1232. The README and with.toml that remained described nothing. The example returns rewritten against the facade surface, after the SQLite facade compiles, as the ruling orders.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#1232 was stacked on #1231's branch and squash-merged into that branch 18 seconds after #1231 merged, so its five fixes never reached main. This PR is that squash cherry-picked onto current main, plus two follow-ups.
The five fixes (4c06152, each with its test; see #1232 for the detail):
stris lent to aconst char *in a raw call too (§16.3c, D47) —SemaDiag.try_ci_coercionno longer gates lending onci_raw_syms.CStr.from_ptr(raw-surface primitive) and an owned-copy conversion.Result[Unit, E]body that falls through after an earlyreturn ErrisOk(())(§4.9, the spec's ownvalidateexample). Closure site waits on Calling a fn-typed parameter that returns Result[Unit, E] fails LLVM verification #1230.@[c_export]defines the prototype a c_imported header declares (the body goes into the existing declaration; LLVM no longer renames itname.1).check_identlooked the name up again and found the other module's private global).Follow-ups:
CStr.to_owned(), per D51 §41 (to_str()is reserved for the validating conversion).examples/c-interopis removed. Five defects the c-interop example exposed: str lending in raw calls, CStr.from_ptr, §4.9 fall-through, @[c_export] over a declared prototype, parameter shadowing #1232's squash already deleted its three source files (staged before the first fix commit and not called out — my omission); the README andwith.tomlthat remained described nothing. Per D51 §66 the example returns after the SQLite facade compiles.Battery, seed-driven at d4e5a88 on current main: build, :fixpoint, :test, :move-audit, :drop-audit, :test-green, :last-green all green.