Skip to content

std, Sema: str.parse() turns text into a number of the type its use demands (#959, D165) - #2752

Merged
ehartford merged 1 commit into
fix-981from
fix-959b
Oct 27, 2026
Merged

ehartford merged 1 commit into
fix-981from
fix-959b

Conversation

@ehartford

@ehartford ehartford commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

std, Sema: str.parse() turns text into a number of the type its use demands (#959, D165)

str had no parse method: f[1].parse() was "unknown method 'parse'
for type '&str'", so a field could not become a number. parse[T: Parse]() -> Option[T] takes its type from its use, as Eric set in the
#2127 review. Two Sema gaps stood in the way (the third, the ??
carrier hint, landed as #2724):

  • check_generic_method_call returned before checking a generic method
    of a builtin owner (type_decl_nodes has no str), so the call
    reached MIR uninstantiated. A builtin owner now has no type parameters
    of its own.
  • a method type parameter no argument mentions was never bound from
    the demand on the result, so let n: Option[i64] = cell.get() was
    "cannot infer generic method type parameter". It is now, as for a free
    generic function.

Parsing is strict (None unless the whole text is one in-range value):
the integer types parse sign and digits; f64 validates the text and
reads strtold's correctly rounded double through rt_core. f32 waits for
its own correctly rounded parse.

Landing str.parse broke text |> parse pipelines naming a program's
own fn parse (behav_pipeline_match, spec_ss09_7_pipeline_match):
check_pipeline committed to a method on existence alone, bound
str.parse[T], and died "cannot infer 'T'". A generic method is now
applicable at a stage only when the stage can instantiate it (§9.6,
D165): every type parameter named by a parameter type, or bound by the
demand on the stage's result (asked speculatively, substitution
restored). Otherwise, when a visible free function shares the name, the
stage is that function. Verified matrix: demand-bound stage takes the
method, undemanded stage takes the program's parse, no free function
keeps the loud cannot-infer error, parse[i64]() spells it.

The census rise that parked the branch was its own ceremony: sixteen
Some(...) wrappers at Option demands in the new string.w code (now
bare values, D103) and two typed field lets in the new Sema code (now
inferred). Counts return to main's (plain-bits 416, the D144 allowance
ceiling; some-at lib 1, src 7).

Tests: behav_959_str_parse_by_use, behav_959_generic_method_typed_by_result
(both fail pre-fix on the installed compiler); the two pipeline_match
fixtures are the collision regression. Delegated under D98 as D165
(renumbers the unmerged fix-959 branch's D160).

…emands (#959, D165)

`str` had no parse method: `f[1].parse()` was "unknown method 'parse'
for type '&str'", so a field could not become a number. `parse[T:
Parse]() -> Option[T]` takes its type from its use, as Eric set in the
#2127 review. Two Sema gaps stood in the way (the third, the `??`
carrier hint, landed as #2724):

- check_generic_method_call returned before checking a generic method
  of a builtin owner (`type_decl_nodes` has no `str`), so the call
  reached MIR uninstantiated. A builtin owner now has no type parameters
  of its own.
- a method type parameter no argument mentions was never bound from
  the demand on the result, so `let n: Option[i64] = cell.get()` was
  "cannot infer generic method type parameter". It is now, as for a free
  generic function.

Parsing is strict (None unless the whole text is one in-range value):
the integer types parse sign and digits; f64 validates the text and
reads strtold's correctly rounded double through rt_core. f32 waits for
its own correctly rounded parse.

Landing str.parse broke `text |> parse` pipelines naming a program's
own `fn parse` (behav_pipeline_match, spec_ss09_7_pipeline_match):
check_pipeline committed to a method on existence alone, bound
str.parse[T], and died "cannot infer 'T'". A generic method is now
applicable at a stage only when the stage can instantiate it (§9.6,
D165): every type parameter named by a parameter type, or bound by the
demand on the stage's result (asked speculatively, substitution
restored). Otherwise, when a visible free function shares the name, the
stage is that function. Verified matrix: demand-bound stage takes the
method, undemanded stage takes the program's parse, no free function
keeps the loud cannot-infer error, `parse[i64]()` spells it.

The census rise that parked the branch was its own ceremony: sixteen
`Some(...)` wrappers at Option demands in the new string.w code (now
bare values, D103) and two typed field lets in the new Sema code (now
inferred). Counts return to main's (plain-bits 416, the D144 allowance
ceiling; some-at lib 1, src 7).

Tests: behav_959_str_parse_by_use, behav_959_generic_method_typed_by_result
(both fail pre-fix on the installed compiler); the two pipeline_match
fixtures are the collision regression. Delegated under D98 as D165
(renumbers the unmerged fix-959 branch's D160).
@ehartford
ehartford added this pull request to stack #2754 October 27, 2026 01:51
@ehartford ehartford changed the title fix 959b std, Sema: str.parse() turns text into a number of the type its use demands (#959, D165) Oct 27, 2026
@ehartford

Copy link
Copy Markdown
Contributor Author

Battery GREEN on the stack top 3e1594f7d (stack #2754: #2750 #2751 #2752 #2753): tools/battery.w rc=0, wall 440s — gate, UAT and battery-checks all green (behavior-tests 1957 files ok; uat 12 pass, 1 skip; every survey "all targets green"). Each layer also passed src/main build :gate on its own commit before the stack battery (fix-2744, fix-981, fix-959b, fix-2530-diag, all rc=0 under the pinned seed). Merging the stack.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant