@@ -50,7 +50,7 @@ elabRecord info doc rsyn fc opts tyn params paramDocs fields fieldDocs cname cdo
50 ttConsTy <-
50 ttConsTy <-
51 case lookupTyExact dconName (tt_ctxt i) of
51 case lookupTyExact dconName (tt_ctxt i) of
52 Just as -> return as
52 Just as -> return as
53− Nothing -> tclift $ tfail $ At fc (Elaborating "record" tyn (InternalMsg "It seems like the constructor for this record has disappeared. :( \n This is a bug. Please report."))
53+ Nothing -> tclift $ tfail $ At fc (Elaborating "record " tyn (InternalMsg "It seems like the constructor for this record has disappeared. :( \n This is a bug. Please report."))
55 -- The arguments to the constructor
55 -- The arguments to the constructor
56 let constructorArgs = getArgTys ttConsTy
56 let constructorArgs = getArgTys ttConsTy
@@ -69,6 +69,10 @@ elabRecord info doc rsyn fc opts tyn params paramDocs fields fieldDocs cname cdo
69 -- Build and elaborate projection functions
69 -- Build and elaborate projection functions
70 elabProj dconName projectors
70 elabProj dconName projectors
72+ logLvl 1 $ "Dependencies: " ++ show fieldDependencies
74+ logLvl 1 $ "Depended on: " ++ show dependedOn
72 -- All things we need to elaborate update functions for, together with a number denoting their position in the constructor.
76 -- All things we need to elaborate update functions for, together with a number denoting their position in the constructor.
73 let updaters = [(n, n', p, t, d, i) | ((n, n', p, t, d), i) <- zip (paramsForElab ++ userFieldsForElab) [0..]]
77 let updaters = [(n, n', p, t, d, i) | ((n, n', p, t, d), i) <- zip (paramsForElab ++ userFieldsForElab) [0..]]
74 -- Build and elaborate update functions
78 -- Build and elaborate update functions
@@ -170,14 +174,6 @@ elabRecord info doc rsyn fc opts tyn params paramDocs fields fieldDocs cname cdo
170 elabProjection info n n' p t' doc rsyn fc target cn phArgs fieldNames i
174 elabProjection info n n' p t' doc rsyn fc target cn phArgs fieldNames i
171 in mapM_ elab fs
175 in mapM_ elab fs
173− projectInType :: [(Name, Name)] -> PTerm -> PTerm
174− projectInType xs = mapPT st
176− st :: PTerm -> PTerm
178− | Just pn <- lookup n xs = PApp fc (PRef fc pn) [pexp recRef]
181 -- | Elaborate the update functions.
177 -- | Elaborate the update functions.
182 elabUp :: Name -> [(Name, Name, Plicity, PTerm, Docstring (Either Err PTerm), Int)] -> Idris ()
178 elabUp :: Name -> [(Name, Name, Plicity, PTerm, Docstring (Either Err PTerm), Int)] -> Idris ()
183 elabUp cn fs = let args = map (uncurry asPRefArg) [(p, n) | (n, _, p, _, _, _) <- fs]
179 elabUp cn fs = let args = map (uncurry asPRefArg) [(p, n) | (n, _, p, _, _, _) <- fs]
@@ -186,14 +182,14 @@ elabRecord info doc rsyn fc opts tyn params paramDocs fields fieldDocs cname cdo
187 -- | Decides whether a setter should be generated for a field or not.
183 -- | Decides whether a setter should be generated for a field or not.
188 optionalSetter :: Name -> Bool
184 optionalSetter :: Name -> Bool
189− optionalSetter n = n `notElem` dependentFields && n `notElem` dependedOn
185+ optionalSetter n = n `elem` dependedOn
191 -- | A map from a field name to the other fields it depends on.
187 -- | A map from a field name to the other fields it depends on.
192 fieldDependencies :: [(Name, [Name])]
188 fieldDependencies :: [(Name, [Name])]
193 fieldDependencies = map (uncurry fieldDep) [(n, t) | (n, _, t) <- fields ++ params]
189 fieldDependencies = map (uncurry fieldDep) [(n, t) | (n, _, t) <- fields ++ params]
195 fieldDep :: Name -> PTerm -> (Name, [Name])
191 fieldDep :: Name -> PTerm -> (Name, [Name])
196− fieldDep n t = ((nsroot n), fieldNames `intersect` allNamesIn t)
192+ fieldDep n t = ((nsroot n), paramNames ++ fieldNames `intersect` allNamesIn t)
198 -- | A list of fields depending on another field.
194 -- | A list of fields depending on another field.
199 dependentFields :: [Name]
195 dependentFields :: [Name]
@@ -223,7 +219,7 @@ elabProjection :: ElabInfo ->
223 [Name] -> -- ^ All Field Names
219 [Name] -> -- ^ All Field Names
224 Int -> -- ^ Argument Index
220 Int -> -- ^ Argument Index
226−elabProjection info cname pname plicity pty pdoc psyn fc tty cn phArgs fnames index
222+elabProjection info cname pname plicity projTy pdoc psyn fc targetTy cn phArgs fnames index
227 = do logLvl 1 $ "Generating Projection for " ++ show pname
223 = do logLvl 1 $ "Generating Projection for " ++ show pname
229 let ty = generateTy
225 let ty = generateTy
@@ -241,13 +237,7 @@ elabProjection info cname pname plicity pty pdoc psyn fc tty cn phArgs fnames in
242 -- | The type of the projection function.
238 -- | The type of the projection function.
243 generateTy :: PDecl
239 generateTy :: PDecl
244− generateTy = PTy pdoc [] psyn fc [] pname $ PPi expl recName tty (mapPT applyProjs pty)
240+ generateTy = PTy pdoc [] psyn fc [] pname $ PPi expl recName targetTy projTy
246− -- | Applies all fields to "rec".
247− applyProjs :: PTerm -> PTerm
248− applyProjs t@(PRef fc name)
249− | (nsroot name) `elem` fnames = PApp fc t [pexp recRef]
252 -- | The left hand side of the projection function.
242 -- | The left hand side of the projection function.
253 generateLhs :: PTerm
243 generateLhs :: PTerm
@@ -303,9 +293,10 @@ elabUpdate info cname pname plicity pty pdoc psyn fc sty cn args fnames i option
304 idrisCatch (do rec_elabDecl info EAll info ty
294 idrisCatch (do rec_elabDecl info EAll info ty
305 rec_elabDecl info EAll info $ PClauses fc [] set_pname [clause])
295 rec_elabDecl info EAll info $ PClauses fc [] set_pname [clause])
296+ (\err -> logLvl 1 $ "Could not generate update function for " ++ show pname)
306− (\err -> if optional
297+ {-if optional
307 then logLvl 1 $ "Could not generate update function for " ++ show pname
298 then logLvl 1 $ "Could not generate update function for " ++ show pname
308− else tclift $ tfail $ At fc (Elaborating "record update function" pname err))
299+ else tclift $ tfail $ At fc (Elaborating "record update function " pname err)) -}
310 -- | The type of the udpate function.
301 -- | The type of the udpate function.
311 generateTy :: PDecl
302 generateTy :: PDecl
@@ -364,3 +355,11 @@ recName :: Name
364recName = sMN 0 "rec"
355recName = sMN 0 "rec"
366recRef = PRef emptyFC recName
357recRef = PRef emptyFC recName
359+projectInType :: [(Name, Name)] -> PTerm -> PTerm
360+projectInType xs = mapPT st
362+ st :: PTerm -> PTerm
364+ | Just pn <- lookup n xs = PApp fc (PRef fc pn) [pexp recRef]