Skip to content

What makes unit be too late? #501

Closed
Closed

Description

@arkiuat
  • The docs state (and have stated for many years) that a unit declaration at the beginning of a file may be preceded only by comments and use statements.
  • However, any declaration of sub EXPORT must precede the unit declaration.
  • Neither requirement seems to be tested in any roast tests that I could find (but I'm still a novice at searching in the roast repo).

The blocked docs issue Raku/doc#2148 is over seven years old, and the problem it describes is still in the current docs.

The statement at issue in the docs is in https://docs.raku.org/language/syntax#package,_module,_class,_role,_and_grammar_declaration and is currently worded as:

you can declare a unit package at the start of the file (preceded only by comments or use statements),

The conflicting (assuming that unit packages can make use of sub EXPORT) statement is in https://docs.raku.org/language/modules#EXPORT :

Please note that EXPORT can't be declared inside a package because it is part of the compunit rather than the package.

This issue is a re-open of the closed rakudo issue rakudo/rakudo#2020 as a problem-solving issue, as suggested at the time that issue was closed.

Activity

  1. added
    documentation
    on Oct 23, 2025
  2. changed the title [-]What makes C<unit> be too late?[/-] [+]What makes `unit` be too late?[/+] on Oct 23, 2025
  3. librasteve commented on Oct 23, 2025

    @librasteve

    does this mean that unit cannot be used with sub EXPORT -or- that you can declare sub EXPORT before the unit line?

    [not asking for ROAST info - just what do es hte latest rakudo do in practice]

  4. arkiuat commented on Oct 23, 2025

    @arkiuat
    Author

    @librasteve, the original issue stated that you can in fact declare any number of subs before a unit package. I just tested declaring an empty sub EXPORT followed by a unit package and got no errors

  5. librasteve commented on Oct 23, 2025

    @librasteve

    tx! so let's document that ;-)

  6. arkiuat commented on Oct 23, 2025

    @arkiuat
    Author

    There was some discussion of that on the other issues linked above, and there's reluctance to document things that ROAST doesn't require, which makes sense, since all such behavior is technically implementation detail and not part of the language we're documenting.

    Discussion to come to a consensus (about what ROAST should require here) got bogged down in the now-closed rakudo issue rakudo/rakudo#2020, which is why I opened this one, because lack of such consensus is what's blocking the docs issue Raku/doc#2148.

    My own opinion about what the consensus seemed to be groping toward is that sub EXPORTand the like should be allowed (like comments and use statements) before a unit declaration, but that any sub not explicitly allowed there should be disallowed.

    By 'and the like' I mean any other ALL-CAPS subs clearly connected to the namespace in question (as EXPORT is) but which for some reason have to live outside that namespace. This is intended to cover both future developments and also possibly other existing language features that I haven't learned about yet: the general principle is that there's an allowlist for this, and anything not on it would cause squawking.

  7. librasteve commented on Oct 23, 2025

    @librasteve

    @arkiuat - I agree

  8. arkiuat commented on Dec 20, 2025

    @arkiuat
    Author

    So should I be trying to write my first ROAST tests then? I think for this one, we want to add it to the spec before changing the doc.

  9. arkiuat commented on Dec 25, 2025

    @arkiuat
    Author

    Not sure how helpful this is, but here's an old discussion of this issue from 2016, that is linked to from current doc.

  10. librasteve commented on Dec 27, 2025

    @librasteve

    @arkiuat - agree that adding to ROAST first is a good plan.

    I have written (literally) a couple of ROAST tests - having seen you work in the docs, I am sure that you will find it straightforward (and of course there are many out there to help if you get stuck)

  11. arkiuat commented on Dec 28, 2025

    @arkiuat
    Author

    @librasteve thanks, but it's not that I'm hesitant to submit a PR for ROAST, or even that I'm not sure how to test for this particular thing. It has just become clear to me that this isn't going to make it to the top of my priorities anytime soon, if ever.

    At worst, the status quo is that anyone can add a unit class/module/package/whatever to the end of any file that doesn't define other classes/packages/etc, as long as it's the last thing in the file, but the docs say that you can't do this, perhaps in hopes of preventing people from making a habit of it. I'm okay with leaving that as is because there are bigger fish to fry, so I'll leave it for someone who cares about it more than I do.

    Originally I was just trying to knock off an old blocked docs issue, but the scope has creeped. We're just talking about a way to save a level of indentation here.

  12. librasteve commented on Dec 29, 2025

    @librasteve

    OK - thanks for explaining - we all have our various foci and time constraints.

    On a matter of "issue etiquette" I personally prefer "issues that we know are real, but have no prospect of getting resourced since we consider them too low priority" be Closed (ie both this problem-solver and the referenced doc issue above), and perhaps marked with a label such as "later" or "punted".

    That way we can try to keep the issue stack tidy and avoid creating new issues that will still be here in 7 years time.

    ymmv ;-)

  13. arkiuat commented on Dec 29, 2025

    @arkiuat
    Author

    Ah, just because it's too low-priority for me doesn't mean it will be too low-priority for the next volunteer who steps up. As you say, mmmv.

    I wouldn't want to close this one without also closing the docs issue that spawned it. Also, this issue, which explicitly seeks to find out what kind of things such a ROAST test should prohibit, has only been open for a couple of months: not enough time for all knowledgeable parties to weigh in on that question.

    Which, come to think of it, is another reason why I'm not eager to try to write a ROAST test for this right now: I'm not sufficiently knowledgeable to make that particular decision.

  14. librasteve commented on Dec 30, 2025

    @librasteve

    lol - ok, fair enough

  15. lizmat commented on Jan 8, 2026

    @lizmat
    Collaborator

    This issue will be discussed in the first Raku Resolutions meeting, see more information at https://dev.to/lizmat/raku-resolutions-17g7

  16. lizmat commented on Jan 17, 2026

    @lizmat
    Collaborator

    Looking at this a little more in depth, I don't see a reason (yet) why it shouldn't be possible to just say (at least in RakuAST):

    The "unit" scope will absorb any code as part of the that scope until the end of the file".

    Perhaps someone can point me to reasons why this shouldn't be the case?

  17. arkiuat commented on Jan 17, 2026

    @arkiuat
    Author

    The "unit" scope will absorb any code as part of the that scope until the end of the file".

    No reasons why we can't say that: it's true even without RakuAST if I understand correctly. The issue is about code that occurs before the unit scope begins.

  18. lizmat commented on Jan 17, 2026

    @lizmat
    Collaborator

    True. I meant "regardless of any code before the unit scope :-)

  19. arkiuat commented on Feb 22, 2026

    @arkiuat
    Author

    This was discussed at the Resolutions meeting yesterday, and while I did speak up to say that I would close the associated docs issue as soon as this issue is resolved, I didn't volunteer to record the resolution that we reached, and honestly, I can't clearly recall what it was.

  20. lizmat commented on Feb 22, 2026

    @lizmat
    Collaborator

    In my recollection the conclusion was:

    • document that unit indicates a scope for the rest of the source (usually a file, but technically could also be a string being EVALled)
    • it should't matter what is before the unit statement (but currently it does, to be fixed in 6.e).
  21. raiph commented on Feb 23, 2026

    @raiph
  22. arkiuat commented on Feb 24, 2026

    @arkiuat
    Author

    Okay, I need to clarify, because I'm a little surprised that I missed such a sweeping change being decided on at a meeting that I attended. (I have no objection to the change, but I guess the full extent wasn't clear to me at the time?)

    My understanding is that the decision reached at the meeting is that, for 6.e, we plan to specify that

    1. unit simply declares a single named scope for the rest of the compilation unit (file, string, etc), allowing the convenient reduction in indentation level, and
    2. unit will no longer prohibit anything being declared before it.

    The plan is to change any tests currently in roast to reflect this, and to remove the doc's current statement that the only things that can appear before a unit are comments and use statements.

    Does anyone have any objections to this?

  23. raiph commented on Feb 25, 2026

    @raiph
  24. arkiuat commented on Feb 25, 2026

    @arkiuat
    Author

    @raiph , thanks. I have edited my comment accordingly.

    I found the official announcement, which answers all my questions, but I'm leaving the comment up as a way of polling for anyone who is surprised by the decision and might object to it.

    In the meantime I have updated the now-unblocked docs issue accordingly, so I'll know what to do when I get to writing that docs PR.

  25. arkiuat commented on Mar 8, 2026

    @arkiuat
    Author

    The mention of the prohibition has been removed from the documentation, and docs issue 2148 has been closed.

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

Metadata

Metadata

Assignees

Labels

documentation

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions