Mercury Bugs - mercury
View Issue Details
0000318mercuryBugpublic2014-02-13 11:312015-10-29 15:23
Reporterwangp 
Assigned Tozs 
PrioritynormalSeverityminorReproducibilityalways
StatusresolvedResolutionfixed 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0000318: pragma foreign_type depends on item order
DescriptionAn error is reported for a pragma foreign_type if the type name is not declared earlier.
TagsNo tags attached.
Attached Files? foreign.m (135) 2014-02-13 11:31
https://bugs.mercurylang.org/file_download.php?file_id=203&type=bug

Notes
(0000646)
juliensf   
2014-02-13 14:41   
That happens because type declarations and pragmas are added to the HLDS during the same pass.
One solution would be to add all the type declarations before adding all the pragmas; the disadvantage of that approach is that it would require another traversal of the parse tree during parse tree -> hlds conversion.
(0000647)
juliensf   
2014-02-13 19:31   
Actually, there's another solution to this, we could allow foreign_type pragmas to act as type declarations.
(0000653)
zs   
2014-03-03 14:13   
I think the right solution is to away with the notion of "passes" over the item list altogether.

I think the one and only pass over the item list should construct a set of cords; one cord for type declarations, one for inst declarations, one for mode declarations, one for pred declarations and so on. Once those cords have been converted to lists, the rest of the code should then process those lists
in the order that their dependencies dictate. One of those dictates would be the need to process type declarations before processing foreign type pragmas.

The main complication is that at the moment, the import status of each item is effectively implicit in the position of the item with respect to status markers in the item list, and the exact details of that dependence are not well documented. Most of those details are obvious, but some are not.
(0000857)
zs   
2015-10-29 15:23   
Fix committed 2015 oct 29.

Issue History
2014-02-13 11:31wangpNew Issue
2014-02-13 11:31wangpFile Added: foreign.m
2014-02-13 14:41juliensfNote Added: 0000646
2014-02-13 19:31juliensfNote Added: 0000647
2014-03-03 14:13zsNote Added: 0000653
2015-10-29 15:23zsNote Added: 0000857
2015-10-29 15:23zsStatusnew => resolved
2015-10-29 15:23zsResolutionopen => fixed
2015-10-29 15:23zsAssigned To => zs