source: doc/proposals/ @ 954c954

Last change on this file since 954c954 was 954c954, checked in by Fangren Yu <f37yu@…>, 14 months ago

Move function argument and return variable declarations from FunctionType? to FunctionDecl?

  • Property mode set to 100644
File size: 2.0 KB
1## Eliminate Variable Declarations in Function Type ##
3The parameters of a function had been living in the wrong place.
5As the function type has no relation with the actual declarations of the variables, but only the types of them, putting declarations in FunctionType is unnecessary.
6Meanwhile, in new-ast data model, the declaration nodes should be kept as unique as possible, since they semantically denote unique objects in the source code. Shared declarations often lead to undesirable behaviors, especially when weak references exist (reminder: currently weak references only point to declarations). They also pose difficulty for implementing correct _functional_ algorithms, as copying a declaration node _should_ always mean creating a new entity.
7In the programming language and type theory model, declarations are also never a part of function type; the functions `int f(int a)` and `int f(int b)` have the exact same type (int)->(int), and representing the type as (int a)->(int b) is misleading.
10## Summary of Changes ##
12- `ast::FunctionDecl`
13Now owns its parameter and return variables directly.
15- `ast::FunctionType`
16Parameter and return types are now pure types (no more decls)
17Forall clause is part of type information so it is still kept.
20Renamed some functions to reflect the changes (decl -> type)
22- Convert.cpp
23Drop decls in function type, unless it is directly in function decl (move them to `FunctionDecl` params and returns)
24Add dummy variable decls while converting back.
26## Relevant Clean-up Work ##
28- CurrentObject.cpp
29No longer has weak references to type nodes and replaced by raw pointers. Using weak pointers do not accomplish anything since a non in-place mutation outside invalidates current iterator anyways and an in-place mutation outside is still seen by the iterator with just a raw pointer.
32`EnumAndPointerDecay` is redundant in `resolveTypeof` and therefore dropped.
33Note: this pass needs some structural change to accommodate the new function type representation.
Note: See TracBrowser for help on using the repository browser.