Fusion icon indicating copy to clipboard operation
Fusion copied to clipboard

Scopes + memory groundwork

Open dphfox opened this issue 2 years ago • 7 comments

Partially implements #269. This PR introduces some groundwork for future memory management changes, and introduces basic support for the 'scoped' memory management pattern (https://fluff.blog/2023/08/30/the-next-ten-years-beyond-maids.html, https://github.com/dphfox/scoped).

  • [x] Move all memory management utilities into a dedicated Memory folder
  • [x] Rename cleanup to doCleanup for consistency (#237)
  • [x] Add destroy methods to all objects
  • [x] Add type information for destroy methods on objects
  • [x] Add cleanup tables as first parameters to all constructors
  • [x] Warn when scopes mismatch for things expected to have the same lifetime
  • [x] Implement scoped() syntax sugar for cleanup tables w/ constructor methods
  • [x] Generate inner scopes for state objects
  • [x] Ensure type checking mostly passes for additions, and note where it does not currently work so it can be targeted for future PRs
  • [x] Update unit tests
  • [ ] Update API reference
    • [x] Restructure API reference to separate types from members
    • [x] Fix Errors page not rendering
    • [x] Remove old errors from Errors page
    • [x] Update formatting of API pages
    • [ ] Create or update documentation pages
      • [ ] Commonly Used
      • [ ] General
        • [ ] Errors
          • [x] cannotAssignProperty
          • [x] cannotConnectChange
          • [x] cannotConnectEvent
          • [x] cannotCreateClass
          • [ ] callbackError
          • [ ] forKeyCollision
          • [ ] forProcessorError
          • [ ] invalidChangeHandler
          • [ ] invalidAttributeChangeHandler
          • [ ] invalidEventHandler
          • [ ] invalidPropertyType
          • [ ] invalidRefType
          • [ ] invalidOutType
          • [ ] invalidAttributeOutType
          • [ ] invalidOutProperty
          • [ ] invalidSpringDamping
          • [ ] invalidSpringSpeed
          • [ ] mistypedSpringDamping
          • [ ] mistypedSpringSpeed
          • [ ] mistypedTweenInfo
          • [ ] noTaskScheduler
          • [ ] springTypeMismatch
          • [ ] stateGetWasRemoved
          • [ ] unknownMessage
          • [ ] unrecognisedChildType
          • [ ] unrecognisedPropertyKey
          • [ ] unrecognisedPropertyStage
        • [x] Types
          • [x] Version
          • [x] Contextual
        • [x] Members
          • [x] version
          • [x] Contextual
      • [x] Memory
        • [x] Types
          • [x] Scope
          • [x] ScopedObject
          • [x] Task
        • [x] Members
          • [x] deriveScope
          • [x] doCleanup
          • [x] scoped
      • [x] State
        • [x] Types
          • [x] CanBeState
          • [x] Computed
          • [x] Dependency
          • [x] Dependent
          • [x] For
          • [x] Observer
          • [x] StateObject
          • [x] Use
          • [x] Value
        • [x] Members
          • [x] Computed
          • [x] ForKeys
          • [x] ForPairs
          • [x] ForValues
          • [x] Observer
          • [x] peek
          • [x] Value
      • [x] Roblox
        • [x] Types
          • [x] Child
          • [x] PropertyTable
          • [x] SpecialKey
        • [x] Members
          • [x] Attribute
          • [x] AttributeChange
          • [x] AttributeOut
          • [x] Children
          • [x] Hydrate
          • [x] New
          • [x] OnChange
          • [x] OnEvent
          • [x] Out
          • [x] Ref
      • [ ] Animation
        • [ ] Types
          • [ ] Animatable
          • [ ] Spring
          • [ ] Tween
        • [ ] Members
          • [ ] Spring
          • [ ] Tween
  • [x] Update examples
  • [x] Update tutorials
    • [x] Write dedicated scopes section before introducing objects
    • [x] Update all code examples to use scopes

dphfox avatar Sep 02 '23 02:09 dphfox

I think it'd be useful to pull in concepts from #220 for the backend implementation of the For objects. This won't be exposed to users yet - and it probably wouldn't be the final implementation because of #205 - but it'll be useful for tidying up those rat's nests and ensuring they have consistent destruction and memory management.

dphfox avatar Nov 26 '23 20:11 dphfox

Working on debugging the unified internal For implementation now.

dphfox avatar Nov 27 '23 14:11 dphfox

Now disposing of unused processors at the right time :)

image

dphfox avatar Nov 27 '23 15:11 dphfox

image

New For object implementations are now passing unit tests.

dphfox avatar Nov 28 '23 18:11 dphfox

I'm running into issues with typechecking that seem hard to surmount. They might actually be bugs in Luau or the luau-lsp plugin.

I'm going to simply try and fix a decent amount of them that seem possible, and leave the rest in so that this can get out the door. I'll redistribute the type checking fixes to another issue/PR somewhere else.

dphfox avatar Dec 04 '23 20:12 dphfox

Examples have now all been updated to use scope syntax, and also have more fully fleshed-out explanations to go along with it. Pleasantly, a lot of the code snippets are simpler now! That's partly thanks to scopes, but also a little bit thanks to improved coding conventions generally.

dphfox avatar Jan 22 '24 02:01 dphfox

Since we're no longer pursuing additional API surface for the time being, this now fully closes #269.

dphfox avatar Jan 30 '24 18:01 dphfox