Forum > Suggestions
Are forward declarations really necessary?
Ryan J:
If compilation speed is badly hurt then I'd rather have my forward declarations but I'm skeptical it's really so slow on modern computers.
I'm trying to envision how this would work and it would basically be crawling all the types looking for undefined types and then resolving them. If there aren't many types in a unit then this isn't so bad. As for the units with lots of types maybe that would be a problem if you were compiling that file often.
I know it won't be added I was curious what other people thought about this because I always feel a little badly when I have to make these forward declaration units when the compiler could doing this for me. :)
PascalDragon:
--- Quote from: Thaddy on February 18, 2024, 10:22:24 am ---Pascal aims to be a single pass compiler (well, FPC isn't strictly speaking).
--- End quote ---
If one only considers the parser then FPC is a single pass compiler (or parser to be more specific).
--- Quote from: Ryan J on February 18, 2024, 10:03:13 am ---My questions is, are these are specific limitations or language philosophies that means this can't be solved?
--- End quote ---
The language philosophy is “declare before use” and is one of the main principles of Pascal along with “separation of declaration and definition” and we uphold these, because they lead to clearer code.
--- Quote from: Ryan J on February 18, 2024, 10:03:13 am ---(many languages do this already).
--- End quote ---
Pascal is not “many languages”. It doesn't follow hypes.
Ryan J:
--- Quote from: cdbc on February 18, 2024, 10:16:05 am ---Hi
I guess, it's the price we pay, for a 'One Pass Compiler'... ;)
Have you tried to work with interfaces, both COM & CORBA, they'll give you more freedom... 8)
Regards Benny
--- End quote ---
Yes you can get fancy in some cases but this is adding more complexity and interfaces have overhead of their own. The problem can be solved by putting all the types in one unit also but that is slow to compile also and we're doing it because the compiler can't resolve types from different units. I love Pascals units but they are crippled by this limitation.
Ryan J:
--- Quote from: TRon on February 18, 2024, 10:16:29 am ---
--- Quote from: Ryan J on February 18, 2024, 10:03:13 am ---I feel like it's in a deficiency of the compiler and it could be resolved using a second pass type resolution system (many languages do this already).
--- End quote ---
There will not be additional passes added to the compiler. This has been discussed multiple times and the standpoint was made clear for each and every discussion. I do not believe that view has changed.
--- End quote ---
Do you have any links to old discussions? I'm curious about the topic because it seems like a legit shortcoming of Pascal which maybe it's time to reconsider given modern hardware. Maybe a single pass compiler was the obvious choice in 1980 but I'm not so sure if this is true in 2024.
Ryan J:
--- Quote from: PascalDragon on February 18, 2024, 01:19:02 pm ---The language philosophy is “declare before use” and is one of the main principles of Pascal along with “separation of declaration and definition” and we uphold these, because they lead to clearer code.
--- End quote ---
To be clear I'm just talking about resolving types from different units which have circular dependancies, not allowing declaring types in any order. The problem can be fixed but moving all types into a single unit but this cripples what's nice about units.
I'm imagining this second pass could be added to the interface section only (so there's no node tree to traverse) and if an undefined type is found then mark it as undefined and when it's found in another unit come back to a list of types which has unresolved references and resolve them. If it was limited to just the interface section it could be feasible I think.
Navigation
[0] Message Index
[#] Next page
[*] Previous page