Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /sml/trunk/src/cm/smlfile/smlinfo.sml
ViewVC logotype

Annotation of /sml/trunk/src/cm/smlfile/smlinfo.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 537 - (view) (download)

1 : blume 275 (*
2 : blume 282 * Bundling information pertaining to one SML source file.
3 :     * - only includes information that does not require running
4 :     * the machine-dependent part of the compiler
5 : blume 275 *
6 :     * (C) 1999 Lucent Technologies, Bell Laboratories
7 :     *
8 :     * Author: Matthias Blume (blume@kurims.kyoto-u.ac.jp)
9 :     *)
10 : blume 270 signature SMLINFO = sig
11 :    
12 :     type info
13 : blume 305 type ord_key = info
14 : blume 270
15 : blume 295 type complainer = GenericVC.ErrorMsg.complainer
16 : blume 297 type ast = GenericVC.Ast.dec
17 :     type region = GenericVC.SourceMap.region
18 : blume 299 type source = GenericVC.Source.inputSource
19 : blume 274
20 : blume 537 type attribs =
21 :     { split: bool, is_rts: bool,
22 :     extra_compenv: GenericVC.Environment.staticEnv option }
23 :    
24 : blume 279 val eq : info * info -> bool (* compares sourcepaths *)
25 :     val compare : info * info -> order (* compares sourcepaths *)
26 :    
27 : blume 487 (* The idea behind "newGeneration" is the following:
28 :     * Before parsing .cm files (on behalf of CM.make/recomp or CMB.make etc.)
29 :     * we start a new generation. While parsing, when we encounter a new
30 :     * SML source we re-use existing information and bump its generation
31 :     * number to "now". After we are done with one group we can safely
32 :     * evict all info records for files in this group if their generation
33 :     * is not "now".
34 :     * Moreover, if we encounter an entry that has a different owner group,
35 :     * we can either signal an error (if the generation is "now" which means
36 :     * that the file was found in another group during the same parse) or
37 :     * issue a "switched groups" warning (if the generation is older than
38 :     * now which means that the file used to be in another group). *)
39 :     val newGeneration : unit -> unit
40 :    
41 : blume 299 val info : GeneralParams.info ->
42 : blume 354 { sourcepath: SrcPath.t,
43 :     group: SrcPath.t * region,
44 : blume 537 sh_spec: Sharing.request }
45 : blume 270 -> info
46 :    
47 : blume 537 val info' : attribs -> GeneralParams.info ->
48 :     { sourcepath: SrcPath.t,
49 :     group: SrcPath.t * region,
50 :     sh_spec: Sharing.request }
51 :     -> info
52 :    
53 : blume 354 val sourcepath : info -> SrcPath.t
54 :     val skelname : info -> string
55 :     val binname : info -> string
56 : blume 299 val error : GeneralParams.info -> info -> complainer
57 : blume 277
58 : blume 299 val parsetree : GeneralParams.info -> info -> (ast * source) option
59 : blume 301 val exports : GeneralParams.info -> info -> SymbolSet.set option
60 :     val skeleton : GeneralParams.info -> info -> Skeleton.decl option
61 : blume 387 val sh_spec : info -> Sharing.request
62 :     val set_sh_mode : info * Sharing.mode -> unit
63 :     val sh_mode : info -> Sharing.mode
64 : blume 537 val attribs : info -> attribs
65 : blume 301 val lastseen : info -> TStamp.t
66 : blume 279
67 : blume 301 (* forget a parse tree that we are done with *)
68 :     val forgetParsetree : info -> unit
69 :    
70 : blume 487 (* Evict all elements that belong to a given group but which
71 :     * are not of the current generation. "cleanGroup" should be
72 : blume 514 * called right after finishing to parse the group file.
73 :     * If the boolean flag ("nowStable") is set to true, then all
74 :     * members of the group are dismissed regardless of their
75 :     * generation. This is used to get rid of the information for
76 :     * members of now-stable libraries. *)
77 :     val cleanGroup : bool -> SrcPath.t -> unit
78 : blume 301
79 : blume 537 (* See if a given piece of info is (still) known here: *)
80 :     val isKnown : info -> bool
81 :    
82 : blume 487 (* Delete all known info. *)
83 :     val reset : unit -> unit
84 :    
85 : blume 280 (* different ways of describing an sml file using group and source *)
86 :     val spec : info -> string (* sspec *)
87 :     val fullSpec : info -> string (* gspec(sspec) *)
88 : blume 354 val descr : info -> string (* sname *)
89 :     val fullDescr : info -> string (* gname(sspec) *)
90 : blume 305
91 : blume 306 val errorLocation : GeneralParams.info -> info -> string
92 : blume 270 end
93 :    
94 :     structure SmlInfo :> SMLINFO = struct
95 :    
96 : blume 275 structure Source = GenericVC.Source
97 :     structure SF = GenericVC.SmlFile
98 :     structure EM = GenericVC.ErrorMsg
99 : blume 286 structure FNP = FilenamePolicy
100 : blume 275
101 :     type source = Source.inputSource
102 : blume 297 type ast = GenericVC.Ast.dec
103 :     type region = GenericVC.SourceMap.region
104 : blume 274
105 : blume 295 type complainer = EM.complainer
106 : blume 274
107 : blume 537 type attribs =
108 :     { split: bool, is_rts: bool,
109 :     extra_compenv: GenericVC.Environment.staticEnv option }
110 :    
111 : blume 487 type generation = unit ref
112 :    
113 : blume 389 (* sh_mode is an elaboration of sh_spec; it must be persistent
114 :     * and gets properly re-computed when there is a new sh_spec *)
115 : blume 297 datatype persinfo =
116 : blume 354 PERS of { group: SrcPath.t * region,
117 : blume 487 generation: generation ref,
118 : blume 297 lastseen: TStamp.t ref,
119 : blume 299 parsetree: (ast * source) option ref,
120 : blume 389 skeleton: Skeleton.decl option ref,
121 :     sh_mode: Sharing.mode ref }
122 : blume 297
123 : blume 275 datatype info =
124 : blume 354 INFO of { sourcepath: SrcPath.t,
125 : blume 361 mkSkelname: unit -> string,
126 :     mkBinname: unit -> string,
127 : blume 297 persinfo: persinfo,
128 : blume 387 sh_spec: Sharing.request,
129 : blume 537 attribs: attribs }
130 : blume 270
131 : blume 305 type ord_key = info
132 :    
133 : blume 487 local
134 :     val generation = ref (ref ())
135 :     in
136 :     fun now () = !generation
137 :     fun newGeneration () = generation := ref ()
138 :     end
139 :    
140 : blume 277 fun sourcepath (INFO { sourcepath = sp, ... }) = sp
141 : blume 361 fun skelname (INFO { mkSkelname = msn, ... }) = msn ()
142 :     fun binname (INFO { mkBinname = mbn, ... }) = mbn ()
143 : blume 387 fun sh_spec (INFO { sh_spec = s, ... }) = s
144 : blume 389 fun sh_mode (INFO { persinfo = PERS { sh_mode = ref m, ... }, ... }) = m
145 :     fun set_sh_mode (INFO { persinfo = PERS { sh_mode, ... }, ... }, m) =
146 :     sh_mode := m
147 : blume 537 fun attribs (INFO { attribs = a, ... }) = a
148 : blume 270
149 : blume 299 fun gerror (gp: GeneralParams.info) = GroupReg.error (#groupreg gp)
150 : blume 297
151 :     fun error gp (INFO { persinfo = PERS { group, ... }, ... }) =
152 :     gerror gp group
153 :    
154 : blume 279 fun compare (INFO { sourcepath = p, ... }, INFO { sourcepath = p', ... }) =
155 : blume 354 SrcPath.compare (p, p')
156 : blume 279 fun eq (i, i') = compare (i, i') = EQUAL
157 :    
158 : blume 301 fun lastseen (INFO { persinfo = PERS { lastseen, ... }, ... }) =
159 :     !lastseen
160 :    
161 : blume 354 val knownInfo = ref (SrcPathMap.empty: persinfo SrcPathMap.map)
162 : blume 277
163 : blume 537 fun isKnown (INFO { sourcepath, ... }) =
164 :     isSome (SrcPathMap.find (!knownInfo, sourcepath))
165 :    
166 : blume 365 fun countParseTrees () = let
167 :     fun one (PERS { parsetree = ref (SOME _), ... }, i) = i + 1
168 :     | one (_, i) = i
169 :     in
170 :     SrcPathMap.foldl one 0 (!knownInfo)
171 :     end
172 :    
173 : blume 301 fun forgetParsetree (INFO { persinfo = PERS { parsetree, ... }, ... }) =
174 :     parsetree := NONE
175 :    
176 : blume 514 fun cleanGroup nowStable g = let
177 : blume 487 val n = now ()
178 :     fun isCurrent (PERS { generation = ref gen, group = (g', _), ... }) =
179 : blume 514 ((not nowStable) andalso gen = n)
180 :     orelse SrcPath.compare (g, g') <> EQUAL
181 : blume 301 in
182 : blume 487 knownInfo := SrcPathMap.filter isCurrent (!knownInfo)
183 : blume 301 end
184 :    
185 : blume 487 fun reset () = knownInfo := SrcPathMap.empty
186 :    
187 : blume 330 (* check timestamp and throw away any invalid cache *)
188 :     fun validate (sourcepath, PERS pir) = let
189 :     (* don't use "..." pattern to have the compiler catch later
190 :     * additions to the type! *)
191 : blume 487 val { group, lastseen, parsetree, skeleton, sh_mode, generation } = pir
192 : blume 330 val ts = !lastseen
193 : blume 354 val nts = SrcPath.tstamp sourcepath
194 : blume 330 in
195 : blume 345 if TStamp.needsUpdate { source = nts, target = ts } then
196 : blume 330 (lastseen := nts;
197 : blume 487 generation := now ();
198 : blume 330 parsetree := NONE;
199 :     skeleton := NONE)
200 :     else ()
201 :     end
202 :    
203 : blume 537 fun info' attribs (gp: GeneralParams.info) arg = let
204 :     val { sourcepath, group = gr as (group, region), sh_spec } = arg
205 : blume 310 val policy = #fnpolicy (#param gp)
206 : blume 361 fun mkSkelname () = FNP.mkSkelName policy sourcepath
207 :     fun mkBinname () = FNP.mkBinName policy sourcepath
208 : blume 297 val groupreg = #groupreg gp
209 :     fun newpersinfo () = let
210 : blume 354 val ts = SrcPath.tstamp sourcepath
211 : blume 330 val pi = PERS { group = gr, lastseen = ref ts,
212 : blume 389 parsetree = ref NONE, skeleton = ref NONE,
213 : blume 487 sh_mode = ref (Sharing.SHARE false),
214 :     generation = ref (now ()) }
215 : blume 281 in
216 : blume 354 knownInfo := SrcPathMap.insert (!knownInfo, sourcepath, pi);
217 : blume 297 pi
218 : blume 281 end
219 : blume 297 fun persinfo () =
220 : blume 354 case SrcPathMap.find (!knownInfo, sourcepath) of
221 : blume 297 NONE => newpersinfo ()
222 : blume 487 | SOME (pi as PERS { group = gr' as (g, r), generation, ... }) =>
223 : blume 354 if SrcPath.compare (group, g) <> EQUAL then let
224 :     val n = SrcPath.descr sourcepath
225 : blume 322 in
226 : blume 487 if !generation = now () then
227 : blume 322 (gerror gp gr EM.COMPLAIN
228 :     (concat ["ML source file ", n,
229 :     " appears in more than one group"])
230 :     EM.nullErrorBody;
231 :     gerror gp gr' EM.COMPLAIN
232 :     (concat ["(previous occurence of ", n, ")"])
233 :     EM.nullErrorBody)
234 :     else
235 :     gerror gp gr EM.WARN
236 :     (concat ["ML source file ", n,
237 :     " has switched groups"])
238 :     EM.nullErrorBody;
239 :     newpersinfo ()
240 :     end
241 : blume 330 else (validate (sourcepath, pi); pi)
242 : blume 281 in
243 : blume 297 INFO { sourcepath = sourcepath,
244 : blume 361 mkSkelname = mkSkelname,
245 :     mkBinname = mkBinname,
246 : blume 297 persinfo = persinfo (),
247 : blume 387 sh_spec = sh_spec,
248 : blume 537 attribs = attribs }
249 : blume 281 end
250 : blume 277
251 : blume 537 val info = info' { split = true, extra_compenv = NONE, is_rts = false }
252 :    
253 : blume 275 (* the following functions are only concerned with getting the data,
254 :     * not with checking time stamps *)
255 : blume 297 fun getParseTree gp (i as INFO ir, quiet, noerrors) = let
256 :     val { sourcepath, persinfo = PERS { parsetree, ... }, ... } = ir
257 : blume 281 val err = if noerrors then (fn m => ())
258 : blume 297 else (fn m => error gp i EM.COMPLAIN m EM.nullErrorBody)
259 : blume 274 in
260 : blume 275 case !parsetree of
261 :     SOME pt => SOME pt
262 :     | NONE => let
263 : blume 345 fun work stream = let
264 :     val _ = if noerrors orelse quiet then ()
265 : blume 354 else Say.vsay ["[parsing ",
266 :     SrcPath.descr sourcepath, "]\n"]
267 : blume 345 val source =
268 : blume 492 Source.newSource (SrcPath.osstring' sourcepath,
269 : blume 354 1, stream, false, #errcons gp)
270 : blume 275 in
271 : blume 345 (SF.parse source, source)
272 :     end
273 : blume 364 fun openIt () = TextIO.openIn (SrcPath.osstring sourcepath)
274 : blume 345 val pto =
275 :     SOME (SafeIO.perform { openIt = openIt,
276 :     closeIt = TextIO.closeIn,
277 :     work = work,
278 : blume 459 cleanup = fn _ => () })
279 : blume 365 (* Counting the trees explicitly may be a bit slow,
280 :     * but maintaining an accurate count is difficult, so
281 :     * this method should be robust. (I don't think that
282 :     * the overhead of counting will make a noticeable
283 :     * difference.) *)
284 :     val ntrees = countParseTrees ()
285 : blume 433 val treelimit = #get StdConfig.parse_caching ()
286 : blume 275 in
287 : blume 365 if ntrees < treelimit then
288 :     parsetree := pto
289 :     else ();
290 : blume 275 pto
291 : blume 345 end handle exn as IO.Io _ => (err (General.exnMessage exn); NONE)
292 :     | SF.Compile msg => (err msg; NONE)
293 : blume 274 end
294 :    
295 : blume 297 fun getSkeleton gp (i as INFO ir, noerrors) = let
296 : blume 361 val { sourcepath, mkSkelname, persinfo = PERS pir, ... } = ir
297 : blume 297 val { skeleton, lastseen, ... } = pir
298 : blume 275 in
299 :     case !skeleton of
300 : blume 301 SOME sk => SOME sk
301 : blume 361 | NONE => let
302 :     val skelname = mkSkelname ()
303 :     in
304 :     case SkelIO.read (skelname, !lastseen) of
305 :     SOME sk => (skeleton := SOME sk; SOME sk)
306 :     | NONE =>
307 :     (case getParseTree gp (i, false, noerrors) of
308 :     SOME (tree, source) => let
309 :     fun err sv region s =
310 :     EM.error source region sv s
311 :     EM.nullErrorBody
312 :     val { skeleton = sk, complain } =
313 :     SkelCvt.convert { tree = tree,
314 :     err = err }
315 :     in
316 :     if noerrors then () else complain ();
317 : blume 310 if EM.anyErrors (EM.errors source) then
318 : blume 361 if noerrors then ()
319 :     else error gp i EM.COMPLAIN
320 : blume 310 "error(s) in ML source file"
321 :     EM.nullErrorBody
322 : blume 354 else (SkelIO.write (skelname, sk, !lastseen);
323 : blume 310 skeleton := SOME sk);
324 :     SOME sk
325 : blume 361 end
326 :     | NONE => NONE)
327 :     end
328 : blume 275 end
329 :    
330 : blume 330 fun skeleton0 noerrors gp i = getSkeleton gp (i, noerrors)
331 : blume 281
332 :     (* we only complain at the time of getting the exports *)
333 : blume 301 fun exports gp i = Option.map SkelExports.exports (skeleton0 false gp i)
334 : blume 281 val skeleton = skeleton0 true
335 : blume 275
336 : blume 330 fun parsetree gp i = getParseTree gp (i, true, true)
337 : blume 282
338 : blume 354 fun spec (INFO { sourcepath, ... }) = SrcPath.specOf sourcepath
339 : blume 297 fun fullSpec (INFO { sourcepath, persinfo = PERS { group, ... }, ... }) =
340 : blume 354 concat [SrcPath.specOf (#1 group), "(", SrcPath.specOf sourcepath, ")"]
341 :     fun descr (INFO { sourcepath, ... }) = SrcPath.descr sourcepath
342 :     fun fullDescr (INFO { sourcepath, persinfo = PERS { group, ... }, ... }) =
343 :     concat [SrcPath.descr (#1 group), "(", SrcPath.specOf sourcepath, ")"]
344 : blume 305
345 : blume 306 fun errorLocation (gp: GeneralParams.info) (INFO i) = let
346 :     val { persinfo = PERS { group = (group, reg), ... }, ... } = i
347 : blume 305 in
348 : blume 306 EM.matchErrorString (GroupReg.lookup (#groupreg gp) group) reg
349 : blume 305 end
350 : blume 270 end

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0