Skip to content

Criteria for putting new unsafe-related text in chapters other than "Unsafe code"  #750

Closed
@RexJaeschke

Description

@RexJaeschke

Note: Since this issue was created, chapter (and maybe section) numbers have changed!

[Although this is an issue for V9, Jon suggested we discuss the general principle soon. That is, how hard should we try to keep all unsafe-related text in the unsafe chapter? Are there reasonable exceptions for not doing so?]

Support for unsafe mode is optional, and 1-2 years ago, we made the decision to push almost all the unsafe-related stuff into the unsafe chapter, §22, except for bits in the grammar, which we’ve flagged as “unsafe-mode only.”

I’ve nearly completed getting the MS v9 proposal for function pointers into shape for use by TG2. However, I have a situation for which I’m looking for guidance.

The addition of support for function pointers requires unsafe support, so most of the spec for that proposal will necessarily go in §22. However, this feature also impacts type inference, as described in six subsections of §11.6.3, “Type inference.”

I see two alternate approaches:

  1. Following the current approach of putting as much as possible unsafe stuff into 22, I can add text to the corresponding sections in §11.6.3.* saying “This subclause is extended in unsafe code (§forward-pointer to §22.x.y).” And then describe those extensions in the new sections §22.x.y.

  2. I can put the unsafe-related stuff in-line in §11.6.3.*, and somehow mark it as being unsafe-related.

Approach 1 is pure, but has the problem that some text in §22.x.y needs to be “merged” into specific places in lists in §11.6.3.*. For example, this would result in the following:

§22.6.(x) Output type inferences [new section]

In §11.6.3.7, the following bullet is added between the second and third bullets:

  • If E is an address-of method group and T is a function pointer type with parameter types T1..Tk and return type Tb, and overload resolution of E with the types T1..Tk yields a single method with return type U, then a lower-bound inference is made from U to Tb.

The reader of this new section, §22.6.x, will have to flip between this text and that in §11.6.3.7 to make sense of it. And then, we are at the mercy of this positional dependence of that list, which could easily get out of sync as §11.6.3.7 evolves.

Here’s a similar case:

§22.6.(y) Lower-bound inferences [new section]

In §11.6.3.10, the following case is added to the third bullet:

  • V is a function pointer type delegate*<V2..Vk, V1> and there is a function pointer type delegate*<U2..Uk, U1> such that U is identical to delegate*<U2..Uk, U1>, and the calling convention of V is identical to U, and the refness of Vi is identical to Ui.

The first bullet of inference from Ui to Vi is modified to:

  • If U is not a function pointer type and Ui is not known to be a reference type, or if U is a function pointer type and Ui is not known to be a function pointer type or a reference type, then an exact inference is made

Then, added after the third bullet of inference from Ui to Vi:

  • Otherwise, if V is delegate*<V2..Vk, V1> then inference depends on the i-th parameter of delegate*<V2..Vk, V1>:
    • If V1:
      • If the return is by value, then a lower-bound inference is made.
      • If the return is by reference, then an exact inference is made.
    • If V2..Vk:
      • If the parameter is by value, then an upper-bound inference is made.
      • If the parameter is by reference, then an exact inference is made.

This enhancement involves a change of existing words, not just the addition of new words, which complicates things further. That said, if we push this stuff back into §11.6.3.x., we likely can find a way to have two branches for this: with and without unsafe support.

The longer I study the problem, the more I lean towards putting this stuff in §11.6.3.* with suitable unsafe-conditional text. Putting it in §22 makes it stand out, but not positively so, and looks somewhat like the situation we had previously with the grammar in earlier chapters being augmented by unsafe extensions in §22. And we dropped that approach and pushed the unsafe grammar back into the main spec.

Metadata

Metadata

Assignees

Labels

meeting: proposalThere is an informal proposal in the issue, worth discussing in a meeting

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions